summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-08-30 19:48:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:30:24 -0500
commit929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291 (patch)
tree169c06d247826eac8c3d3054ce8de78fce7d454d /source3/smbd
parenta646210b2b8ead5690b3c6baf058c2de6e0c1a26 (diff)
downloadsamba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.gz
samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.bz2
samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.zip
r24809: Consolidate the use of temporary talloc contexts.
This adds the two functions talloc_stackframe() and talloc_tos(). * When a new talloc stackframe is allocated with talloc_stackframe(), then * the TALLOC_CTX returned with talloc_tos() is reset to that new * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse * happens: The previous talloc_tos() is restored. * * This API is designed to be robust in the sense that if someone forgets to * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and * resets the talloc_tos(). The original motivation for this patch was to get rid of the sid_string_static & friends buffers. Explicitly passing talloc context everywhere clutters code too much for my taste, so an implicit talloc_tos() is introduced here. Many of these static buffers are replaced by a single static pointer. The intended use would thus be that low-level functions can rather freely push stuff to talloc_tos, the upper layers clean up by freeing the stackframe. The more of these stackframes are used and correctly freed the more exact the memory cleanup happens. This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and lp_talloc_ctx (did I forget any?) So, never do a tmp_ctx = talloc_init("foo"); anymore, instead, use tmp_ctx = talloc_stackframe() :-) Volker (This used to be commit 6585ea2cb7f417e14540495b9c7380fe9c8c717b)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/blocking.c4
-rw-r--r--source3/smbd/lanman.c2
-rw-r--r--source3/smbd/negprot.c2
-rw-r--r--source3/smbd/notify.c2
-rw-r--r--source3/smbd/nttrans.c2
-rw-r--r--source3/smbd/open.c4
-rw-r--r--source3/smbd/posix_acls.c4
-rw-r--r--source3/smbd/process.c10
-rw-r--r--source3/smbd/server.c3
-rw-r--r--source3/smbd/trans2.c4
10 files changed, 16 insertions, 21 deletions
diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c
index 3bf6e0f99a..ef70829f74 100644
--- a/source3/smbd/blocking.c
+++ b/source3/smbd/blocking.c
@@ -255,7 +255,7 @@ static void reply_lockingX_success(blocking_lock_record *blr)
{
struct smb_request *req;
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
smb_panic("Could not allocate smb_request");
}
@@ -526,7 +526,7 @@ static BOOL process_trans2(blocking_lock_record *blr)
/* We finally got the lock, return success. */
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
blocking_lock_reply_error(blr, NT_STATUS_NO_MEMORY);
return True;
}
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index 1d6369c18b..581ac90aeb 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -4216,7 +4216,7 @@ static BOOL api_RNetSessionEnum(connection_struct *conn, uint16 vuid,
return False;
}
- num_sessions = list_sessions(tmp_talloc_ctx(), &session_list);
+ num_sessions = list_sessions(talloc_tos(), &session_list);
if (mdrcnt > 0) {
*rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
diff --git a/source3/smbd/negprot.c b/source3/smbd/negprot.c
index 4437f0bd3f..98109a2149 100644
--- a/source3/smbd/negprot.c
+++ b/source3/smbd/negprot.c
@@ -543,7 +543,7 @@ void reply_negprot(connection_struct *conn, struct smb_request *req)
char **tmp;
- tmp = TALLOC_REALLOC_ARRAY(tmp_talloc_ctx(), cliprotos, char *,
+ tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), cliprotos, char *,
num_cliprotos+1);
if (tmp == NULL) {
DEBUG(0, ("talloc failed\n"));
diff --git a/source3/smbd/notify.c b/source3/smbd/notify.c
index 0bdf466092..da80c25407 100644
--- a/source3/smbd/notify.c
+++ b/source3/smbd/notify.c
@@ -176,7 +176,7 @@ void change_notify_reply(const uint8 *request_buf, uint32 max_param,
goto done;
}
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
change_notify_reply_packet(request_buf, NT_STATUS_NO_MEMORY);
goto done;
}
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index f5c5db72a0..b5af173d45 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -1484,7 +1484,7 @@ static void call_nt_transact_create(connection_struct *conn,
pdata = data + sd_len;
/* We have already checked that ea_len <= data_count here. */
- ea_list = read_nttrans_ea_list(tmp_talloc_ctx(), pdata,
+ ea_list = read_nttrans_ea_list(talloc_tos(), pdata,
ea_len);
if (!ea_list ) {
TALLOC_FREE(case_state);
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 725d72b284..6efef2f912 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1159,7 +1159,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
return print_fsp_open(conn, fname, result);
}
- if (!parent_dirname_talloc(tmp_talloc_ctx(), fname, &parent_dir,
+ if (!parent_dirname_talloc(talloc_tos(), fname, &parent_dir,
&newname)) {
return NT_STATUS_NO_MEMORY;
}
@@ -1979,7 +1979,7 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
return status;
}
- if (!parent_dirname_talloc(tmp_talloc_ctx(), name, &parent_dir,
+ if (!parent_dirname_talloc(talloc_tos(), name, &parent_dir,
&dirname)) {
return NT_STATUS_NO_MEMORY;
}
diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c
index 6286cd0414..64051d23b1 100644
--- a/source3/smbd/posix_acls.c
+++ b/source3/smbd/posix_acls.c
@@ -2971,14 +2971,14 @@ size_t get_nt_acl(files_struct *fsp, uint32 security_info, SEC_DESC **ppdesc)
}
if (num_aces) {
- if((psa = make_sec_acl( main_loop_talloc_get(), NT4_ACL_REVISION, num_aces, nt_ace_list)) == NULL) {
+ if((psa = make_sec_acl( talloc_tos(), NT4_ACL_REVISION, num_aces, nt_ace_list)) == NULL) {
DEBUG(0,("get_nt_acl: Unable to malloc space for acl.\n"));
goto done;
}
}
} /* security_info & DACL_SECURITY_INFORMATION */
- psd = make_standard_sec_desc( main_loop_talloc_get(),
+ psd = make_standard_sec_desc( talloc_tos(),
(security_info & OWNER_SECURITY_INFORMATION) ? &owner_sid : NULL,
(security_info & GROUP_SECURITY_INFORMATION) ? &group_sid : NULL,
psa,
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 99898141db..8b3e85f4b4 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -1125,7 +1125,7 @@ static void construct_reply(char *inbuf, int size)
file_chain_reset();
reset_chain_p();
- if (!(req = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req = talloc(talloc_tos(), struct smb_request))) {
smb_panic("could not allocate smb_request");
}
init_smb_request(req, (uint8 *)inbuf);
@@ -1346,7 +1346,7 @@ void chain_reply(struct smb_request *req)
DEBUG(3,("Chained message\n"));
show_msg(inbuf2);
- if (!(req2 = talloc(tmp_talloc_ctx(), struct smb_request))) {
+ if (!(req2 = talloc(talloc_tos(), struct smb_request))) {
smb_panic("could not allocate smb_request");
}
init_smb_request(req2, (uint8 *)inbuf2);
@@ -1634,13 +1634,10 @@ void smbd_process(void)
int num_echos;
char *inbuf;
size_t inbuf_len;
+ TALLOC_CTX *frame = talloc_stackframe();
errno = 0;
- /* free up temporary memory */
- lp_TALLOC_FREE();
- main_loop_TALLOC_FREE();
-
/* Did someone ask for immediate checks on things like blocking locks ? */
if (select_timeout == 0) {
if(!timeout_processing(&select_timeout,
@@ -1713,5 +1710,6 @@ void smbd_process(void)
change_to_root_user();
check_log_size();
}
+ TALLOC_FREE(frame);
}
}
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 7e55d3c086..72eeb7ee6a 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -384,9 +384,6 @@ static BOOL open_sockets_smbd(enum smb_server_mode server_mode, const char *smb_
fd_set r_fds, w_fds;
int num;
- /* Free up temporary memory from the main smbd. */
- lp_TALLOC_FREE();
-
/* Ensure we respond to PING and DEBUG messages from the main smbd. */
message_dispatch(smbd_messaging_context());
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index dd3363b20c..ed4d4554d4 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -888,7 +888,7 @@ static void call_trans2open(connection_struct *conn,
return;
}
- ea_list = read_ea_list(tmp_talloc_ctx(), pdata + 4,
+ ea_list = read_ea_list(talloc_tos(), pdata + 4,
total_data - 4);
if (!ea_list) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
@@ -6613,7 +6613,7 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req,
return;
}
- ea_list = read_ea_list(tmp_talloc_ctx(), pdata + 4,
+ ea_list = read_ea_list(talloc_tos(), pdata + 4,
total_data - 4);
if (!ea_list) {
reply_nterror(req, NT_STATUS_INVALID_PARAMETER);