r24809: Consolidate the use of temporary talloc contexts.
authorVolker Lendecke <vlendec@samba.org>
Thu, 30 Aug 2007 19:48:31 +0000 (19:48 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:30:24 +0000 (12:30 -0500)
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)

33 files changed:
source3/Makefile.in
source3/include/includes.h
source3/include/talloc_stack.h [new file with mode: 0644]
source3/lib/talloc_stack.c [new file with mode: 0644]
source3/modules/nfs4_acls.c
source3/modules/vfs_afsacl.c
source3/modules/vfs_aixacl2.c
source3/modules/vfs_gpfs.c
source3/modules/vfs_zfsacl.c
source3/nmbd/nmbd.c
source3/nsswitch/winbindd.c
source3/nsswitch/winbindd_dual.c
source3/param/loadparm.c
source3/rpc_parse/parse_lsa.c
source3/rpc_parse/parse_misc.c
source3/rpc_parse/parse_ntsvcs.c
source3/rpc_parse/parse_spoolss.c
source3/rpc_parse/parse_svcctl.c
source3/rpc_server/srv_pipe.c
source3/rpc_server/srv_spoolss_nt.c
source3/rpc_server/srv_srvsvc_nt.c
source3/smbd/blocking.c
source3/smbd/lanman.c
source3/smbd/negprot.c
source3/smbd/notify.c
source3/smbd/nttrans.c
source3/smbd/open.c
source3/smbd/posix_acls.c
source3/smbd/process.c
source3/smbd/server.c
source3/smbd/trans2.c
source3/utils/net_lookup.c
source3/utils/net_sam.c

index 924dbb203ef108f2c301cf69d65aa17c28c7dde5..fe2336ff917201989389b06d17204fd68c527bb1 100644 (file)
@@ -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 \
index a5c6eec33dda44484e260390b0d4d3b2eadf57c6..5bb7227d0bbadf265d561dbbe285374775e402a7 100644 (file)
@@ -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 (file)
index 0000000..331893c
--- /dev/null
@@ -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 (file)
index 0000000..baebbd4
--- /dev/null
@@ -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];
+}
index 200f87a559822341f5b0aa5f500195504d01d814..31a9b01619c459f15f3f0c87c9b9e588f76c4864 100644 (file)
@@ -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"));
 
index 633b4e2ccda80a21eec0875b7de32696a12b56df..ba0ced9a4f8d63c35fd3ae602e2666d68bf52208 100644 (file)
@@ -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;
index b4e28be5d8c567c1c58863f2045060586b64ead0..8226ccd33d1dda56c6a349f5d25f28b0739c8592 100644 (file)
@@ -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)
index 393efd2328d4f889fbcc8784566094ec3fb34310..b8e8209be0752b0f019d56b60efada145273584e 100644 (file)
@@ -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);
index 9217d4c8bc0369b5c6d869434444d7007e732aa8..fd057fa08935d1df6cc8047021cc1e6b05a89d3e 100644 (file)
@@ -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;
index 9c8c764763c601aab601f057b2f6f8eb8d7d64b0..b9d78a8ba9e0668b52c82dd161e3dd3efa9b2436 100644 (file)
@@ -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);
        }
 }
 
index ecc30e140a160c4f412e2375822b0c90ad00637f..d7368a3d34330a08a9be79e2cea7493d180d3d00 100644 (file)
@@ -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);
        }
 }
 
index b79445ee865b56c55e8d7aaf26913162dab3631d..4263d722a186b0c96af21265db0d1088254ddec9 100644 (file)
@@ -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);
        }
 }
index 7e573052e18e449ca7efeff0644c4a346e96909e..3dd94645fd0f9adc030b181976623b1047add373 100644 (file)
@@ -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 "";
        }               
index c6727d83b5365be75d13c8ec3ef3d246a96b741b..625ef5fb41ff6e63dd255201ab547be561b5cb30 100644 (file)
@@ -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;
index 15a71a11be931b5cd3aca3daedce506f4c4ccc9e..54d8ae4785310a7d629c48a3c93a1b89a68edf8b 100644 (file)
 #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");
 
index 93061deb35b52b7655a95640f141df961cb6c7f0..bcf3f55bd0b304e18e51208d583e8419fb9969e5 100644 (file)
@@ -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;
                        }
index 99470c476c4712f7c1e737c3e7c85f6797774260..a0d818bd67ae5f5f464ec66160124c76b4494421 100644 (file)
@@ -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;
        }
index b366b14e7f80f4280cdf2374aad02dd039961014..b571034d4cc7e8afdf7cbbf9da7927bf39943c69 100644 (file)
@@ -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;
                        }
index 7493aaddb9ecfc2ec1a327be0f61937a3e032080..fefdb529b2cc1647d09a50de8f696d1e2f929916 100644 (file)
@@ -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",
index b50e1e7558fa9dd2803d0d008199d5f2477be18f..600eb2f688caf423b25a4223615d4cea940f6035 100644 (file)
@@ -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 );
        }
 
index ed32f6a765c4d8e544d6619a5f54bf5b6b8de5c8..22eaac51a75075f9fa40b5260d7a435efb918ee1 100644 (file)
@@ -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;
 
index 3bf6e0f99ab1a1d6c7b5d78d1936dd4ac050ebd8..ef70829f746f93c3be90cffdaf546d87147eb657 100644 (file)
@@ -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;
        }
index 1d6369c18b57cc29761db9a0b36856ae87af0d11..581ac90aeb611f063b1328af4f27fccfe98633cc 100644 (file)
@@ -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);
index 4437f0bd3f5e55333321bc47999f0dddb810dca4..98109a2149f660d59a390b82cafa77832393bfa1 100644 (file)
@@ -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"));
index 0bdf466092c625e8458426bf07469d00732f5fd2..da80c25407b918a3429e885fa0b3f260b2f0e931 100644 (file)
@@ -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;
        }
index f5c5db72a0e9ead052fd9d738023658a734407c5..b5af173d45ed3f74cff3f3198019b67182da3a36 100644 (file)
@@ -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);
index 725d72b28417c7d9f25b25fc2e40d611bb65a408..6efef2f912f324ba85b54696c56ae585b5317d4f 100644 (file)
@@ -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;
        }
index 6286cd04145fb40a7fa209a8714b96a53a63da72..64051d23b1291205734091d0b3ca2f76fe8cc338 100644 (file)
@@ -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,
index 99898141db9b9e523117170418d0a583550461c0..8b3e85f4b41e8d72fd58c088ff1e9b09c25d5902 100644 (file)
@@ -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);
        }
 }
index 7e55d3c08651d13d784b1c663394292d8414702c..72eeb7ee6a8f20c46aabc0b6ca4253a74df0d274 100644 (file)
@@ -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());
 
index dd3363b20ccaf785d9aeb9dbea52435345f13e78..ed4d4554d4c1b0be8671b833801d92fc94a499a1 100644 (file)
@@ -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);
index a775afcdc1fcbe770c58925e7e7bfc98bac38ce8..29fea32c9b7391af612ae806e9d53c36be8947cf 100644 (file)
@@ -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;
index 09eb57f95fe87009c93fc9953bce274b26922acb..3cc838e71b83bad304a2dbef807d7aec46fd1fb7 100644 (file)
@@ -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;