summaryrefslogtreecommitdiff
path: root/source3
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
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')
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/includes.h1
-rw-r--r--source3/include/talloc_stack.h55
-rw-r--r--source3/lib/talloc_stack.c108
-rw-r--r--source3/modules/nfs4_acls.c8
-rw-r--r--source3/modules/vfs_afsacl.c12
-rw-r--r--source3/modules/vfs_aixacl2.c4
-rw-r--r--source3/modules/vfs_gpfs.c4
-rw-r--r--source3/modules/vfs_zfsacl.c4
-rw-r--r--source3/nmbd/nmbd.c15
-rw-r--r--source3/nsswitch/winbindd.c8
-rw-r--r--source3/nsswitch/winbindd_dual.c9
-rw-r--r--source3/param/loadparm.c44
-rw-r--r--source3/rpc_parse/parse_lsa.c8
-rw-r--r--source3/rpc_parse/parse_misc.c84
-rw-r--r--source3/rpc_parse/parse_ntsvcs.c4
-rw-r--r--source3/rpc_parse/parse_spoolss.c10
-rw-r--r--source3/rpc_parse/parse_svcctl.c2
-rw-r--r--source3/rpc_server/srv_pipe.c4
-rw-r--r--source3/rpc_server/srv_spoolss_nt.c6
-rw-r--r--source3/rpc_server/srv_srvsvc_nt.c5
-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
-rw-r--r--source3/utils/net_lookup.c4
-rw-r--r--source3/utils/net_sam.c38
33 files changed, 272 insertions, 204 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 924dbb203e..fe2336ff91 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -267,7 +267,7 @@ TALLOC_OBJ = lib/talloc/talloc.o
LIB_WITHOUT_PROTO_OBJ = $(LIBREPLACE_OBJ) $(SOCKET_WRAPPER_OBJ) $(TALLOC_OBJ) \
lib/messages.o librpc/gen_ndr/ndr_messaging.o lib/messages_local.o \
- lib/messages_ctdbd.o lib/packet.o lib/ctdbd_conn.o
+ lib/messages_ctdbd.o lib/packet.o lib/ctdbd_conn.o lib/talloc_stack.o
LIB_WITH_PROTO_OBJ = $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \
lib/interface.o lib/md4.o \
diff --git a/source3/include/includes.h b/source3/include/includes.h
index a5c6eec33d..5bb7227d0b 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -708,6 +708,7 @@ typedef int BOOL;
#include "dbwrap.h"
#include "packet.h"
#include "ctdbd_conn.h"
+#include "talloc_stack.h"
/*
* Type for wide character dirent structure.
diff --git a/source3/include/talloc_stack.h b/source3/include/talloc_stack.h
new file mode 100644
index 0000000000..331893cbd6
--- /dev/null
+++ b/source3/include/talloc_stack.h
@@ -0,0 +1,55 @@
+/*
+ Unix SMB/CIFS implementation.
+ Implement a stack of talloc contexts
+ Copyright (C) Volker Lendecke 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ * Implement a stack of talloc frames.
+ *
+ * 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().
+ *
+ */
+
+#ifndef _TALLOC_STACK_H
+#define _TALLOC_STACK_H
+
+#include "lib/talloc/talloc.h"
+
+/*
+ * Create a new talloc stack frame.
+ *
+ * When free'd, it frees all stack frames that were created after this one and
+ * not explicitly freed.
+ */
+
+TALLOC_CTX *talloc_stackframe(void);
+
+/*
+ * Get us the current top of the talloc stack.
+ */
+
+TALLOC_CTX *talloc_tos(void);
+
+#endif
diff --git a/source3/lib/talloc_stack.c b/source3/lib/talloc_stack.c
new file mode 100644
index 0000000000..baebbd4fac
--- /dev/null
+++ b/source3/lib/talloc_stack.c
@@ -0,0 +1,108 @@
+/*
+ Unix SMB/CIFS implementation.
+ Implement a stack of talloc contexts
+ Copyright (C) Volker Lendecke 2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ * Implement a stack of talloc frames.
+ *
+ * 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().
+ *
+ * This robustness feature means that we can't rely on a linked list with
+ * talloc destructors because in a hierarchy of talloc destructors the parent
+ * destructor is called before its children destructors. The child destructor
+ * called after the parent would set the talloc_tos() to the wrong value.
+ */
+
+#include "includes.h"
+
+static int talloc_stacksize;
+static TALLOC_CTX **talloc_stack;
+
+static int talloc_pop(int *ptr)
+{
+ int tos = *ptr;
+ int i;
+
+ for (i=talloc_stacksize-1; i>=tos; i--) {
+ talloc_free(talloc_stack[i]);
+ }
+
+ talloc_stacksize = tos;
+ return 0;
+}
+
+/*
+ * Create a new talloc stack frame.
+ *
+ * When free'd, it frees all stack frames that were created after this one and
+ * not explicitly freed.
+ */
+
+TALLOC_CTX *talloc_stackframe(void)
+{
+ TALLOC_CTX **tmp, *top;
+ int *cleanup;
+
+ if (!(tmp = TALLOC_REALLOC_ARRAY(NULL, talloc_stack, TALLOC_CTX *,
+ talloc_stacksize + 1))) {
+ goto fail;
+ }
+
+ talloc_stack = tmp;
+
+ if (!(top = talloc_new(talloc_stack))) {
+ goto fail;
+ }
+
+ if (!(cleanup = talloc(top, int))) {
+ goto fail;
+ }
+
+ *cleanup = talloc_stacksize;
+ talloc_set_destructor(cleanup, talloc_pop);
+
+ talloc_stack[talloc_stacksize++] = top;
+
+ return top;
+
+ fail:
+ smb_panic("talloc_stackframe failed");
+ return NULL;
+}
+
+/*
+ * Get us the current top of the talloc stack.
+ */
+
+TALLOC_CTX *talloc_tos(void)
+{
+ if (talloc_stacksize == 0) {
+ DEBUG(0, ("no talloc stackframe around, leaking memory\n"));
+ talloc_stackframe();
+ }
+
+ return talloc_stack[talloc_stacksize-1];
+}
diff --git a/source3/modules/nfs4_acls.c b/source3/modules/nfs4_acls.c
index 200f87a559..31a9b01619 100644
--- a/source3/modules/nfs4_acls.c
+++ b/source3/modules/nfs4_acls.c
@@ -82,7 +82,7 @@ static SMB_ACE4_INT_T *get_validated_aceint(SMB4ACE_T *ace)
SMB4ACL_T *smb_create_smb4acl(void)
{
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
SMB_ACL4_INT_T *acl = (SMB_ACL4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACL4_INT_T));
if (acl==NULL)
{
@@ -98,7 +98,7 @@ SMB4ACL_T *smb_create_smb4acl(void)
SMB4ACE_T *smb_add_ace4(SMB4ACL_T *acl, SMB_ACE4PROP_T *prop)
{
SMB_ACL4_INT_T *aclint = get_validated_aclint(acl);
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
SMB_ACE4_INT_T *ace;
ace = (SMB_ACE4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACE4_INT_T));
@@ -267,7 +267,7 @@ size_t smb_get_nt_acl_nfs4(files_struct *fsp,
size_t sd_size = 0;
SEC_ACE *nt_ace_list = NULL;
SEC_ACL *psa = NULL;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
DEBUG(10, ("smb_get_nt_acl_nfs4 invoked for %s\n", fsp->fsp_name));
@@ -529,7 +529,7 @@ static SMB4ACL_T *smbacl4_win2nfs4(
{
SMB4ACL_T *acl;
uint32 i;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
DEBUG(10, ("smbacl4_win2nfs4 invoked\n"));
diff --git a/source3/modules/vfs_afsacl.c b/source3/modules/vfs_afsacl.c
index 633b4e2ccd..ba0ced9a4f 100644
--- a/source3/modules/vfs_afsacl.c
+++ b/source3/modules/vfs_afsacl.c
@@ -141,7 +141,7 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx,
if (string_to_sid(&sid, name)) {
const char *user, *domain;
/* We have to find the type, look up the SID */
- lookup_sid(tmp_talloc_ctx(), &sid,
+ lookup_sid(talloc_tos(), &sid,
&domain, &user, &type);
}
@@ -155,7 +155,7 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx,
*p = '\\';
}
- if (!lookup_name(tmp_talloc_ctx(), name, LOOKUP_NAME_ALL,
+ if (!lookup_name(talloc_tos(), name, LOOKUP_NAME_ALL,
&domain, &uname, &sid, &type)) {
DEBUG(10, ("Could not find AFS user %s\n", name));
@@ -597,7 +597,7 @@ static size_t afs_to_nt_acl(struct afs_acl *afs_acl,
SEC_ACL *psa = NULL;
int good_aces;
size_t sd_size;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
struct afs_ace *afs_ace;
@@ -753,7 +753,7 @@ static BOOL nt_to_afs_acl(const char *filename,
} else {
- if (!lookup_sid(tmp_talloc_ctx(), &ace->trustee,
+ if (!lookup_sid(talloc_tos(), &ace->trustee,
&dom_name, &name, &name_type)) {
DEBUG(1, ("AFSACL: Could not lookup SID %s on file %s\n",
sid_string_static(&ace->trustee), filename));
@@ -764,7 +764,7 @@ static BOOL nt_to_afs_acl(const char *filename,
(name_type == SID_NAME_DOM_GRP) ||
(name_type == SID_NAME_ALIAS) ) {
char *tmp;
- tmp = talloc_asprintf(tmp_talloc_ctx(), "%s%s%s",
+ tmp = talloc_asprintf(talloc_tos(), "%s%s%s",
dom_name, lp_winbind_separator(),
name);
if (tmp == NULL) {
@@ -777,7 +777,7 @@ static BOOL nt_to_afs_acl(const char *filename,
if (sidpts) {
/* Expect all users/groups in pts as SIDs */
name = talloc_strdup(
- tmp_talloc_ctx(),
+ talloc_tos(),
sid_string_static(&ace->trustee));
if (name == NULL) {
return False;
diff --git a/source3/modules/vfs_aixacl2.c b/source3/modules/vfs_aixacl2.c
index b4e28be5d8..8226ccd33d 100644
--- a/source3/modules/vfs_aixacl2.c
+++ b/source3/modules/vfs_aixacl2.c
@@ -66,7 +66,7 @@ static AIXJFS2_ACL_T *aixjfs2_getacl_alloc(const char *fname, acl_type_t *type)
uint64_t ctl_flag=0;
TALLOC_CTX *mem_ctx;
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
acl = (AIXJFS2_ACL_T *)TALLOC_SIZE(mem_ctx, len);
if (acl == NULL) {
errno = ENOMEM;
@@ -303,7 +303,7 @@ static BOOL aixjfs2_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
DEBUG(10, ("jfs2_process_smbacl invoked on %s\n", fsp->fsp_name));
/* no need to be freed which is alloced with mem_ctx */
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
entryLen = sizeof(nfs4_ace_int_t);
if (entryLen & 0x03)
diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index 393efd2328..b8e8209be0 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -101,7 +101,7 @@ static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type
struct gpfs_acl *acl;
size_t len = 200;
int ret;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
if (acl == NULL) {
@@ -267,7 +267,7 @@ static BOOL gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
gpfs_aclLen_t gacl_len;
SMB4ACE_T *smbace;
struct gpfs_acl *gacl;
- TALLOC_CTX *mem_ctx = main_loop_talloc_get();
+ TALLOC_CTX *mem_ctx = talloc_tos();
gacl_len = sizeof(struct gpfs_acl) +
(smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t);
diff --git a/source3/modules/vfs_zfsacl.c b/source3/modules/vfs_zfsacl.c
index 9217d4c8bc..fd057fa089 100644
--- a/source3/modules/vfs_zfsacl.c
+++ b/source3/modules/vfs_zfsacl.c
@@ -53,7 +53,7 @@ static size_t zfs_get_nt_acl(struct files_struct *fsp, uint32 security_info,
return 0;
}
/* allocate the field of ZFS aces */
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
acebuf = (ace_t *) talloc_size(mem_ctx, sizeof(ace_t)*naces);
if(acebuf == NULL) {
errno = ENOMEM;
@@ -102,7 +102,7 @@ static BOOL zfs_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
TALLOC_CTX *mem_ctx;
/* allocate the field of ZFS aces */
- mem_ctx = main_loop_talloc_get();
+ mem_ctx = talloc_tos();
acebuf = (ace_t *) talloc_size(mem_ctx, sizeof(ace_t)*naces);
if(acebuf == NULL) {
errno = ENOMEM;
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 9c8c764763..b9d78a8ba9 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -372,6 +372,7 @@ static void process(void)
while( True ) {
time_t t = time(NULL);
+ TALLOC_CTX *frame = talloc_stackframe();
/* Check for internal messages */
@@ -390,8 +391,10 @@ static void process(void)
* (nmbd_packets.c)
*/
- if(listen_for_packets(run_election))
+ if(listen_for_packets(run_election)) {
+ TALLOC_FREE(frame);
return;
+ }
/*
* Handle termination inband.
@@ -583,18 +586,22 @@ static void process(void)
NULL, MSG_SMB_CONF_UPDATED,
procid_self(), &blob);
- if(no_subnets)
+ if(no_subnets) {
+ TALLOC_FREE(frame);
return;
+ }
reload_after_sighup = 0;
}
/* check for new network interfaces */
- if(reload_interfaces(t))
+ if(reload_interfaces(t)) {
+ TALLOC_FREE(frame);
return;
+ }
/* free up temp memory */
- lp_TALLOC_FREE();
+ TALLOC_FREE(frame);
}
}
diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c
index ecc30e140a..d7368a3d34 100644
--- a/source3/nsswitch/winbindd.c
+++ b/source3/nsswitch/winbindd.c
@@ -755,11 +755,6 @@ static int process_loop(int listen_sock, int listen_priv_sock)
rescan_trusted_domains();
- /* Free up temporary memory */
-
- lp_TALLOC_FREE();
- main_loop_TALLOC_FREE();
-
/* Initialise fd lists for select() */
maxfd = MAX(listen_sock, listen_priv_sock);
@@ -938,12 +933,14 @@ static void winbindd_process_loop(enum smb_server_mode server_mode)
}
for (;;) {
+ TALLOC_CTX *frame = talloc_stackframe();
int clients = process_loop(listen_public, listen_priv);
/* Don't bother figuring out the idle time if we won't be
* timing out anyway.
*/
if (idle_timeout_sec < 0) {
+ TALLOC_FREE(frame);
continue;
}
@@ -960,6 +957,7 @@ static void winbindd_process_loop(enum smb_server_mode server_mode)
} else {
starttime = timeval_current();
}
+ TALLOC_FREE(frame);
}
}
diff --git a/source3/nsswitch/winbindd_dual.c b/source3/nsswitch/winbindd_dual.c
index b79445ee86..4263d722a1 100644
--- a/source3/nsswitch/winbindd_dual.c
+++ b/source3/nsswitch/winbindd_dual.c
@@ -1048,10 +1048,7 @@ static BOOL fork_domain_child(struct winbindd_child *child)
struct timeval t;
struct timeval *tp;
struct timeval now;
-
- /* free up any talloc memory */
- lp_TALLOC_FREE();
- main_loop_TALLOC_FREE();
+ TALLOC_CTX *frame = talloc_stackframe();
run_events(winbind_event_context(), 0, NULL, NULL);
@@ -1082,16 +1079,19 @@ static BOOL fork_domain_child(struct winbindd_child *child)
if (ret == 0) {
DEBUG(11,("nothing is ready yet, continue\n"));
+ TALLOC_FREE(frame);
continue;
}
if (ret == -1 && errno == EINTR) {
/* We got a signal - continue. */
+ TALLOC_FREE(frame);
continue;
}
if (ret == -1 && errno != EINTR) {
DEBUG(0,("select error occured\n"));
+ TALLOC_FREE(frame);
perror("select");
return False;
}
@@ -1127,5 +1127,6 @@ static BOOL fork_domain_child(struct winbindd_child *child)
DEBUG(0, ("Could not write result\n"));
exit(1);
}
+ TALLOC_FREE(frame);
}
}
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 7e573052e1..3dd94645fd 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1708,33 +1708,6 @@ static void init_globals(BOOL first_time_only)
Globals.bRegistryShares = False;
}
-static TALLOC_CTX *lp_talloc;
-
-/******************************************************************* a
- Free up temporary memory - called from the main loop.
-********************************************************************/
-
-void lp_TALLOC_FREE(void)
-{
- if (!lp_talloc)
- return;
- TALLOC_FREE(lp_talloc);
- lp_talloc = NULL;
-}
-
-TALLOC_CTX *tmp_talloc_ctx(void)
-{
- if (lp_talloc == NULL) {
- lp_talloc = talloc_init("tmp_talloc_ctx");
- }
-
- if (lp_talloc == NULL) {
- smb_panic("Could not create temporary talloc context");
- }
-
- return lp_talloc;
-}
-
/*******************************************************************
Convenience routine to grab string parameters into temporary memory
and run standard_sub_basic on them. The buffers can be written to by
@@ -1754,9 +1727,6 @@ static char *lp_string(const char *s)
DEBUG(10, ("lp_string(%s)\n", s));
#endif
- if (!lp_talloc)
- lp_talloc = talloc_init("lp_talloc");
-
tmpstr = alloc_sub_basic(get_current_username(),
current_user_info.domain, s);
if (trim_char(tmpstr, '\"', '\"')) {
@@ -1766,7 +1736,7 @@ static char *lp_string(const char *s)
current_user_info.domain, s);
}
}
- ret = talloc_strdup(lp_talloc, tmpstr);
+ ret = talloc_strdup(talloc_tos(), tmpstr);
SAFE_FREE(tmpstr);
return (ret);
@@ -2352,7 +2322,7 @@ static int lp_enum(const char *s,const struct enum_list *_enum)
/* Return parametric option from a given service. Type is a part of option before ':' */
/* Parametric option has following syntax: 'Type: option = value' */
-/* the returned value is talloced in lp_talloc */
+/* the returned value is talloced on the talloc_tos() */
char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def)
{
param_opt_struct *data = get_parametrics(snum, type, option);
@@ -3917,10 +3887,8 @@ static const char *append_ldap_suffix( const char *str )
const char *suffix_string;
- if (!lp_talloc)
- lp_talloc = talloc_init("lp_talloc");
-
- suffix_string = talloc_asprintf( lp_talloc, "%s,%s", str, Globals.szLdapSuffix );
+ suffix_string = talloc_asprintf(talloc_tos(), "%s,%s", str,
+ Globals.szLdapSuffix );
if ( !suffix_string ) {
DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n"));
return "";
@@ -5567,8 +5535,6 @@ void gfree_loadparm(void)
struct file_lists *next;
int i;
- lp_TALLOC_FREE();
-
/* Free the file lists */
f = file_lists;
@@ -5912,7 +5878,7 @@ const char *volume_label(int snum)
}
/* This returns a 33 byte guarenteed null terminated string. */
- ret = talloc_strndup(main_loop_talloc_get(), label, 32);
+ ret = talloc_strndup(talloc_tos(), label, 32);
if (!ret) {
return "";
}
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index c6727d83b5..625ef5fb41 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.c
@@ -3222,13 +3222,13 @@ NTSTATUS init_r_enum_acct_rights( LSA_R_ENUM_ACCT_RIGHTS *out, PRIVILEGE_SET *pr
for ( i=0; i<privileges->count; i++ ) {
privname = luid_to_privilege_name( &privileges->set[i].luid );
if ( privname ) {
- if ( !add_string_to_array( get_talloc_ctx(), privname, &privname_array, &num_priv ) )
+ if ( !add_string_to_array( talloc_tos(), privname, &privname_array, &num_priv ) )
return NT_STATUS_NO_MEMORY;
}
}
if ( num_priv ) {
- out->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+ out->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
if (!out->rights) {
return NT_STATUS_NO_MEMORY;
}
@@ -3299,7 +3299,7 @@ void init_q_add_acct_rights( LSA_Q_ADD_ACCT_RIGHTS *in, POLICY_HND *hnd,
in->pol = *hnd;
init_dom_sid2(&in->sid, sid);
- in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+ in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
if (!in->rights) {
smb_panic("init_q_add_acct_rights: talloc fail\n");
return;
@@ -3367,7 +3367,7 @@ void init_q_remove_acct_rights(LSA_Q_REMOVE_ACCT_RIGHTS *in,
in->removeall = removeall;
in->count = count;
- in->rights = TALLOC_P( get_talloc_ctx(), UNISTR4_ARRAY );
+ in->rights = TALLOC_P( talloc_tos(), UNISTR4_ARRAY );
if (!in->rights) {
smb_panic("init_q_remove_acct_rights: talloc fail\n");
return;
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index 15a71a11be..54d8ae4785 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -25,68 +25,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_PARSE
-/****************************************************************************
- A temporary TALLOC context for things like unistrs, that is valid for
- the life of a complete RPC call.
-****************************************************************************/
-
-static TALLOC_CTX *current_rpc_talloc = NULL;
-
-static TALLOC_CTX *get_current_rpc_talloc(void)
-{
- return current_rpc_talloc;
-}
-
-void set_current_rpc_talloc( TALLOC_CTX *ctx)
-{
- current_rpc_talloc = ctx;
-}
-
-static TALLOC_CTX *main_loop_talloc = NULL;
-
-/*******************************************************************
-free up temporary memory - called from the main loop
-********************************************************************/
-
-void main_loop_TALLOC_FREE(void)
-{
- if (!main_loop_talloc)
- return;
- talloc_destroy(main_loop_talloc);
- main_loop_talloc = NULL;
-}
-
-/*******************************************************************
- Get a talloc context that is freed in the main loop...
-********************************************************************/
-
-TALLOC_CTX *main_loop_talloc_get(void)
-{
- if (!main_loop_talloc) {
- main_loop_talloc = talloc_init("main loop talloc (mainly parse_misc)");
- if (!main_loop_talloc)
- smb_panic("main_loop_talloc: malloc fail");
- }
-
- return main_loop_talloc;
-}
-
-/*******************************************************************
- Try and get a talloc context. Get the rpc one if possible, else
- get the main loop one. The main loop one is more dangerous as it
- goes away between packets, the rpc one will stay around for as long
- as a current RPC lasts.
-********************************************************************/
-
-TALLOC_CTX *get_talloc_ctx(void)
-{
- TALLOC_CTX *tc = get_current_rpc_talloc();
-
- if (tc)
- return tc;
- return main_loop_talloc_get();
-}
-
/*******************************************************************
Reads or writes a UTIME type.
********************************************************************/
@@ -449,7 +387,7 @@ void init_unistr(UNISTR *str, const char *buf)
len = strlen(buf) + 1;
if (len) {
- str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
if (str->buffer == NULL)
smb_panic("init_unistr: malloc fail");
@@ -485,7 +423,7 @@ BOOL smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth)
static void create_rpc_blob(RPC_DATA_BLOB *str, size_t len)
{
if (len) {
- str->buffer = (uint8 *)TALLOC_ZERO(get_talloc_ctx(), len);
+ str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(), len);
if (str->buffer == NULL)
smb_panic("create_rpc_blob: talloc fail");
str->buf_len = len;
@@ -591,7 +529,7 @@ void init_regval_buffer(REGVAL_BUFFER *str, const uint8 *buf, size_t len)
if (buf != NULL) {
SMB_ASSERT(str->buf_max_len >= str->buf_len);
- str->buffer = (uint16 *)TALLOC_ZERO(get_talloc_ctx(),
+ str->buffer = (uint16 *)TALLOC_ZERO(talloc_tos(),
str->buf_max_len);
if (str->buffer == NULL)
smb_panic("init_regval_buffer: talloc fail");
@@ -668,7 +606,7 @@ void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
reallocation of memory. */
if (str->buffer == NULL) {
if (str->uni_max_len) {
- str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_max_len);
+ str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_max_len);
if ((str->buffer == NULL)) {
smb_panic("copy_unistr2: talloc fail");
return;
@@ -701,7 +639,7 @@ void init_string2(STRING2 *str, const char *buf, size_t max_len, size_t str_len)
/* store the string */
if(str_len != 0) {
- str->buffer = (uint8 *)TALLOC_ZERO(get_talloc_ctx(),
+ str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(),
str->str_max_len);
if (str->buffer == NULL)
smb_panic("init_string2: malloc fail");
@@ -778,7 +716,7 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
}
- str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
if (str->buffer == NULL) {
smb_panic("init_unistr2: malloc fail");
return;
@@ -814,7 +752,7 @@ void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags)
{
- uni4->string = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ uni4->string = TALLOC_P( talloc_tos(), UNISTR2 );
if (!uni4->string) {
smb_panic("init_unistr4: talloc fail");
return;
@@ -913,7 +851,7 @@ void init_unistr2_from_unistr(UNISTR2 *to, const UNISTR *from)
/* allocate the space and copy the string buffer */
if (i) {
- to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);
+ to->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, i);
if (to->buffer == NULL)
smb_panic("init_unistr2_from_unistr: malloc fail");
memcpy(to->buffer, from->buffer, i*sizeof(uint16));
@@ -1117,7 +1055,7 @@ BOOL prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRA
if (UNMARSHALLING(ps)) {
if (array->count) {
- if ( !(array->strings = TALLOC_ZERO_ARRAY( get_talloc_ctx(), UNISTR4, array->count)) )
+ if ( !(array->strings = TALLOC_ZERO_ARRAY( talloc_tos(), UNISTR4, array->count)) )
return False;
} else {
array->strings = NULL;
@@ -1152,7 +1090,7 @@ BOOL init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **string
/* allocate memory for the array of UNISTR4 objects */
if (array->count) {
- if ( !(array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR4, count )) )
+ if ( !(array->strings = TALLOC_ZERO_ARRAY(talloc_tos(), UNISTR4, count )) )
return False;
} else {
array->strings = NULL;
@@ -1707,7 +1645,7 @@ void init_unistr3(UNISTR3 *str, const char *buf)
str->uni_str_len = strlen(buf) + 1;
if (str->uni_str_len) {
- str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, str->uni_str_len);
+ str->str.buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_str_len);
if (str->str.buffer == NULL)
smb_panic("init_unistr3: malloc fail");
diff --git a/source3/rpc_parse/parse_ntsvcs.c b/source3/rpc_parse/parse_ntsvcs.c
index 93061deb35..bcf3f55bd0 100644
--- a/source3/rpc_parse/parse_ntsvcs.c
+++ b/source3/rpc_parse/parse_ntsvcs.c
@@ -299,7 +299,7 @@ BOOL ntsvcs_io_q_get_hw_profile_info(const char *desc, NTSVCS_Q_GET_HW_PROFILE_I
q_u->buffer_size = 0x000000a8;
if ( UNMARSHALLING(ps) ) {
- q_u->buffer = TALLOC_ARRAY(get_talloc_ctx(), uint8, q_u->buffer_size );
+ q_u->buffer = TALLOC_ARRAY(talloc_tos(), uint8, q_u->buffer_size );
if (!q_u->buffer) {
return False;
}
@@ -334,7 +334,7 @@ BOOL ntsvcs_io_r_get_hw_profile_info(const char *desc, NTSVCS_R_GET_HW_PROFILE_I
if ( UNMARSHALLING(ps) ) {
if (r_u->buffer_size) {
- r_u->buffer = TALLOC_ARRAY(get_talloc_ctx(), uint8, r_u->buffer_size );
+ r_u->buffer = TALLOC_ARRAY(talloc_tos(), uint8, r_u->buffer_size );
if (!r_u->buffer) {
return False;
}
diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c
index 99470c476c..a0d818bd67 100644
--- a/source3/rpc_parse/parse_spoolss.c
+++ b/source3/rpc_parse/parse_spoolss.c
@@ -905,7 +905,7 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
{
DEBUG(5,("make_spoolss_q_open_printer_ex\n"));
- q_u->printername = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ q_u->printername = TALLOC_P( talloc_tos(), UNISTR2 );
if (!q_u->printername) {
return False;
}
@@ -921,7 +921,7 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
q_u->user_switch = 1;
q_u->user_ctr.level = 1;
- q_u->user_ctr.user.user1 = TALLOC_P( get_talloc_ctx(), SPOOL_USER_1 );
+ q_u->user_ctr.user.user1 = TALLOC_P( talloc_tos(), SPOOL_USER_1 );
if (!q_u->user_ctr.user.user1) {
return False;
}
@@ -931,11 +931,11 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
q_u->user_ctr.user.user1->minor = 0;
q_u->user_ctr.user.user1->processor = 0;
- q_u->user_ctr.user.user1->client_name = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ q_u->user_ctr.user.user1->client_name = TALLOC_P( talloc_tos(), UNISTR2 );
if (!q_u->user_ctr.user.user1->client_name) {
return False;
}
- q_u->user_ctr.user.user1->user_name = TALLOC_P( get_talloc_ctx(), UNISTR2 );
+ q_u->user_ctr.user.user1->user_name = TALLOC_P( talloc_tos(), UNISTR2 );
if (!q_u->user_ctr.user.user1->user_name) {
return False;
}
@@ -986,7 +986,7 @@ BOOL make_spoolss_q_addprinterex( TALLOC_CTX *mem_ctx, SPOOL_Q_ADDPRINTEREX *q_u
q_u->user_switch=1;
q_u->user_ctr.level = 1;
- q_u->user_ctr.user.user1 = TALLOC_P( get_talloc_ctx(), SPOOL_USER_1 );
+ q_u->user_ctr.user.user1 = TALLOC_P( talloc_tos(), SPOOL_USER_1 );
if (!q_u->user_ctr.user.user1) {
return False;
}
diff --git a/source3/rpc_parse/parse_svcctl.c b/source3/rpc_parse/parse_svcctl.c
index b366b14e7f..b571034d4c 100644
--- a/source3/rpc_parse/parse_svcctl.c
+++ b/source3/rpc_parse/parse_svcctl.c
@@ -783,7 +783,7 @@ BOOL svcctl_io_service_fa( const char *desc, SERVICE_FAILURE_ACTIONS *fa, RPC_BU
if ( UNMARSHALLING(ps)) {
if (fa->num_actions) {
- if ( !(fa->actions = TALLOC_ARRAY( get_talloc_ctx(), SC_ACTION, fa->num_actions )) ) {
+ if ( !(fa->actions = TALLOC_ARRAY( talloc_tos(), SC_ACTION, fa->num_actions )) ) {
DEBUG(0,("svcctl_io_service_fa: talloc() failure!\n"));
return False;
}
diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c
index 7493aaddb9..fefdb529b2 100644
--- a/source3/rpc_server/srv_pipe.c
+++ b/source3/rpc_server/srv_pipe.c
@@ -2240,9 +2240,9 @@ BOOL api_pipe_request(pipes_struct *p)
pipe_fns = find_pipe_fns_by_context(p->contexts, p->hdr_req.context_id);
if ( pipe_fns ) {
- set_current_rpc_talloc(p->mem_ctx);
+ TALLOC_CTX *frame = talloc_stackframe();
ret = api_rpcTNP(p, p->name, pipe_fns->cmds, pipe_fns->n_cmds);
- set_current_rpc_talloc(NULL);
+ TALLOC_FREE(frame);
}
else {
DEBUG(0,("api_pipe_request: No rpc function table associated with context [%d] on pipe [%s]\n",
diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c
index b50e1e7558..600eb2f688 100644
--- a/source3/rpc_server/srv_spoolss_nt.c
+++ b/source3/rpc_server/srv_spoolss_nt.c
@@ -389,7 +389,7 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number,
DEBUG(4,("short name:%s\n", Printer->sharename));
*number = print_queue_snum(Printer->sharename);
if ((*number != -1) && (params != NULL)) {
- *params = get_share_params(tmp_talloc_ctx(),
+ *params = get_share_params(talloc_tos(),
Printer->sharename);
if (*params == NULL) {
return False;
@@ -4257,7 +4257,7 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd,
/* don't use talloc_steal() here unless you do a deep steal of all
the SEC_DESC members */
- printer->secdesc = dup_sec_desc( get_talloc_ctx(),
+ printer->secdesc = dup_sec_desc( talloc_tos(),
ntprinter->info_2->secdesc_buf->sd );
}
@@ -4297,7 +4297,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd,
/* don't use talloc_steal() here unless you do a deep steal of all
the SEC_DESC members */
- printer->secdesc = dup_sec_desc( get_talloc_ctx(),
+ printer->secdesc = dup_sec_desc( talloc_tos(),
ntprinter->info_2->secdesc_buf->sd );
}
diff --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c
index ed32f6a765..22eaac51a7 100644
--- a/source3/rpc_server/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srv_srvsvc_nt.c
@@ -1049,7 +1049,6 @@ static WERROR init_srv_conn_info_ctr(pipes_struct *p, union srvsvc_NetConnCtr *c
static WERROR net_file_enum_3(pipes_struct *p, union srvsvc_NetFileCtr *ctr, uint32 *resume_hnd, uint32 *num_entries )
{
- TALLOC_CTX *ctx = get_talloc_ctx();
WERROR status;
/* TODO -- Windows enumerates
@@ -1058,11 +1057,11 @@ static WERROR net_file_enum_3(pipes_struct *p, union srvsvc_NetFileCtr *ctr, uin
ctr->ctr3 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetFileCtr3);
- status = net_enum_files( ctx, &ctr->ctr3->array, num_entries, resume_hnd );
+ status = net_enum_files(p->mem_ctx, &ctr->ctr3->array, num_entries, resume_hnd );
if ( !W_ERROR_IS_OK(status))
return status;
- status = net_enum_pipes( ctx, &ctr->ctr3->array, num_entries, resume_hnd );
+ status = net_enum_pipes(p->mem_ctx, &ctr->ctr3->array, num_entries, resume_hnd );
if ( !W_ERROR_IS_OK(status))
return status;
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);
diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index a775afcdc1..29fea32c9b 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -299,7 +299,7 @@ static int net_lookup_name(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ALL,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ALL,
&dom, &name, &sid, &type)) {
d_printf("Could not lookup name %s\n", argv[0]);
return -1;
@@ -326,7 +326,7 @@ static int net_lookup_sid(int argc, const char **argv)
return -1;
}
- if (!lookup_sid(tmp_talloc_ctx(), &sid,
+ if (!lookup_sid(talloc_tos(), &sid,
&dom, &name, &type)) {
d_printf("Could not lookup name %s\n", argv[0]);
return -1;
diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c
index 09eb57f95f..3cc838e71b 100644
--- a/source3/utils/net_sam.c
+++ b/source3/utils/net_sam.c
@@ -41,7 +41,7 @@ static int net_sam_userset(int argc, const char **argv, const char *field,
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -138,7 +138,7 @@ static int net_sam_set_userflag(int argc, const char **argv, const char *field,
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -222,7 +222,7 @@ static int net_sam_set_pwdmustchangenow(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -283,7 +283,7 @@ static int net_sam_set_comment(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -520,18 +520,18 @@ static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *pmap)
map.gid = grp->gr_gid;
grpname = grp->gr_name;
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
&dom, &name, NULL, NULL)) {
const char *tmp = talloc_asprintf(
- tmp_talloc_ctx(), "Unix Group %s", grp->gr_name);
+ talloc_tos(), "Unix Group %s", grp->gr_name);
DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
grpname, dom, name, tmp));
grpname = tmp;
}
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
NULL, NULL, NULL, NULL)) {
DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
return NT_STATUS_GROUP_EXISTS;
@@ -551,7 +551,7 @@ static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *pmap)
sid_compose(&map.sid, get_global_sam_sid(), rid);
map.sid_name_use = SID_NAME_DOM_GRP;
- fstrcpy(map.comment, talloc_asprintf(tmp_talloc_ctx(), "Unix Group %s",
+ fstrcpy(map.comment, talloc_asprintf(talloc_tos(), "Unix Group %s",
grp->gr_name));
status = pdb_add_group_mapping_entry(&map);
@@ -606,7 +606,7 @@ static NTSTATUS unmap_unix_group(const struct group *grp, GROUP_MAP *pmap)
map.gid = grp->gr_gid;
grpname = grp->gr_name;
- if (!lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
NULL, NULL, NULL, NULL)) {
DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
return NT_STATUS_NO_SUCH_GROUP;
@@ -702,7 +702,7 @@ static int net_sam_deletelocalgroup(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find %s.\n", argv[0]);
return -1;
@@ -755,7 +755,7 @@ static int net_sam_createbuiltingroup(int argc, const char **argv)
fstrcpy( groupname, "BUILTIN\\" );
fstrcat( groupname, argv[0] );
- if ( !lookup_name(tmp_talloc_ctx(), groupname, LOOKUP_NAME_ALL, NULL,
+ if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
NULL, &sid, &type)) {
d_fprintf(stderr, "%s is not a BUILTIN group\n", argv[0]);
return -1;
@@ -795,7 +795,7 @@ static int net_sam_addmem(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
@@ -803,7 +803,7 @@ static int net_sam_addmem(int argc, const char **argv)
/* check to see if the member to be added is a name or a SID */
- if (!lookup_name(tmp_talloc_ctx(), argv[1], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_ISOLATED,
&memberdomain, &membername, &member, &membertype))
{
/* try it as a SID */
@@ -813,7 +813,7 @@ static int net_sam_addmem(int argc, const char **argv)
return -1;
}
- if ( !lookup_sid(tmp_talloc_ctx(), &member, &memberdomain,
+ if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
&membername, &membertype) )
{
d_fprintf(stderr, "Could not resolve SID %s\n", argv[1]);
@@ -868,13 +868,13 @@ static int net_sam_delmem(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[1], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_ISOLATED,
&memberdomain, &membername, &member, NULL)) {
if (!string_to_sid(&member, argv[1])) {
d_fprintf(stderr, "Could not find member %s\n",
@@ -926,7 +926,7 @@ static int net_sam_listmem(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
@@ -949,7 +949,7 @@ static int net_sam_listmem(int argc, const char **argv)
(unsigned int)num_members);
for (i=0; i<num_members; i++) {
const char *dom, *name;
- if (lookup_sid(tmp_talloc_ctx(), &members[i],
+ if (lookup_sid(talloc_tos(), &members[i],
&dom, &name, NULL)) {
d_printf(" %s\\%s\n", dom, name);
} else {
@@ -1076,7 +1076,7 @@ static int net_sam_show(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;