r1983: a completely new implementation of talloc
authorAndrew Tridgell <tridge@samba.org>
Sat, 21 Aug 2004 01:54:46 +0000 (01:54 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:58:14 +0000 (12:58 -0500)
This version does the following:

  1) talloc_free(), talloc_realloc() and talloc_steal() lose their
     (redundent) first arguments

  2) you can use _any_ talloc pointer as a talloc context to allocate
     more memory. This allows you to create complex data structures
     where the top level structure is the logical parent of the next
     level down, and those are the parents of the level below
     that. Then destroy either the lot with a single talloc_free() or
     destroy any sub-part with a talloc_free() of that part

  3) you can name any pointer. Use talloc_named() which is just like
     talloc() but takes the printf style name argument as well as the
     parent context and the size.

The whole thing ends up being a very simple piece of code, although
some of the pointer walking gets hairy.

So far, I'm just using the new talloc() like the old one. The next
step is to actually take advantage of the new interface
properly. Expect some new commits soon that simplify some common
coding styles in samba4 by using the new talloc().
(This used to be commit e35bb094c52e550b3105dd1638d8d90de71d854f)

43 files changed:
source4/auth/auth_sam.c
source4/include/talloc.h
source4/lib/data_blob.c
source4/lib/registry/common/reg_interface.c
source4/lib/registry/reg_backend_dir/reg_backend_dir.c
source4/lib/registry/reg_backend_gconf/reg_backend_gconf.c
source4/lib/registry/reg_backend_ldb/reg_backend_ldb.c
source4/lib/talloc.c
source4/lib/tallocmsg.c
source4/lib/util_str.c
source4/lib/util_unistr.c
source4/lib/util_uuid.c
source4/libads/ldap.c
source4/libcli/clilist.c
source4/libcli/ldap/ldap.c
source4/libcli/ldap/ldap_ldif.c
source4/libcli/raw/clisession.c
source4/libcli/raw/clisocket.c
source4/libcli/raw/clitransport.c
source4/libcli/raw/clitree.c
source4/libcli/raw/raweas.c
source4/libcli/raw/rawfile.c
source4/libcli/raw/rawfileinfo.c
source4/libcli/raw/rawreadwrite.c
source4/libcli/raw/rawrequest.c
source4/libcli/raw/rawtrans.c
source4/librpc/ndr/ndr.c
source4/librpc/rpc/dcerpc.c
source4/librpc/rpc/dcerpc_smb.c
source4/ntvfs/ipc/ipc_rap.c
source4/ntvfs/reference/ref_util.c
source4/ntvfs/simple/svfs_util.c
source4/ntvfs/simple/vfs_simple.c
source4/rpc_server/dcerpc_server.c
source4/rpc_server/epmapper/rpc_epmapper.c
source4/rpc_server/netlogon/dcerpc_netlogon.c
source4/rpc_server/samr/dcesrv_samr.c
source4/smb_server/request.c
source4/smb_server/trans2.c
source4/torture/rap/rap.c
source4/torture/raw/open.c
source4/torture/raw/search.c
source4/torture/rpc/winreg.c

index b4dc29be85ee783540ac19bddb32f5334f9e1f9f..d83d25c42c374ea8998a6de285b41f196924623e 100644 (file)
@@ -339,7 +339,7 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context,
                }
                
                if (group_ret > 0 && 
-                   !(groupSIDs = talloc_realloc_p((*server_info)->mem_ctx, groupSIDs, 
+                   !(groupSIDs = talloc_realloc_p(groupSIDs, 
                                                   struct dom_sid *, group_ret))) {
                        talloc_destroy((*server_info)->mem_ctx);
                        samdb_close(sam_ctx);
index 8c1a72677874d8d75bbe0d1977eddf4d69ad2c46..dec004b7ef5462b807d0b73f68f973d0743bc833 100644 (file)
@@ -3,8 +3,8 @@
 /* 
    Unix SMB/CIFS implementation.
    Samba temporary memory allocation functions
-   Copyright (C) Andrew Tridgell 2000
-   Copyright (C) 2001 by Martin Pool <mbp@samba.org>
+
+   Copyright (C) Andrew Tridgell 2004
    
    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
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-/**
- * @ingroup talloc
- * @{
- * @sa talloc.c
- */
-
-/**
- * talloc allocation pool.  All allocated blocks can be freed in one go.
- **/
-typedef struct talloc_ctx TALLOC_CTX;
-
-TALLOC_CTX *talloc_init(char const *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
-
-char *talloc_vasprintf(TALLOC_CTX *t, const char *fmt, va_list ap)
-       PRINTF_ATTRIBUTE(2, 0);
-
-char *talloc_asprintf(TALLOC_CTX *t, const char *fmt, ...)
-       PRINTF_ATTRIBUTE(2, 3);
-
-char *talloc_vasprintf_append(TALLOC_CTX *t, char *, const char *, va_list ap)
-       PRINTF_ATTRIBUTE(3, 0);
-
-char *talloc_asprintf_append(TALLOC_CTX *t, char *, const char *, ...)
-       PRINTF_ATTRIBUTE(3, 4);
+/* this is only needed for compatibility with the old talloc */
+typedef void TALLOC_CTX;
 
 /* useful macros for creating type checked pointers */
 #define talloc_p(ctx, type) (type *)talloc(ctx, sizeof(type))
-#define talloc_array_p(ctx, type, count) (type *)talloc_realloc_array(ctx, NULL, sizeof(type), count)
-#define talloc_realloc_p(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count)
+#define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count)
+#define talloc_realloc_p(p, type, count) (type *)talloc_realloc_array(p, sizeof(type), count)
+
+#define talloc_destroy(ctx) talloc_free(ctx)
 
 #define malloc_p(type) (type *)malloc(sizeof(type))
 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
 
-/** @} */
+#endif
 
-#endif /* ndef _TALLOC_H_ */
index ee7bffdc1b3c11f3ac59e8a959571fbf017bf084..bc5cf9abc869f83232f25646e22077e10acde5a2 100644 (file)
@@ -108,7 +108,7 @@ DATA_BLOB data_blob_talloc_steal(TALLOC_CTX *old_ctx, TALLOC_CTX *new_ctx,
 {
        DATA_BLOB new;
        new = *old;
-       new.data = talloc_steal(old_ctx, new_ctx, old->data);
+       new.data = talloc_steal(new_ctx, old->data);
        if (new.data == NULL) {
                smb_panic("data_blob_talloc_steal: talloc_steal failed.\n");
        }
index 0a0cf05c2e3f9211cd8554a3045e4d4183554f0c..e7024d23fea90a9ce0b39b684e93ebaf0d368561 100644 (file)
@@ -214,7 +214,7 @@ WERROR reg_open_key(REG_KEY *parent, const char *name, REG_KEY **result)
        (*result)->path = talloc_asprintf((*result)->mem_ctx, "%s\\%s", 
                                                                 reg_key_get_path_abs(parent), (*result)->name);
        (*result)->hive = parent->hive;
-       talloc_steal(mem_ctx, (*result)->mem_ctx, fullname);
+       talloc_steal((*result)->mem_ctx, fullname);
 
        talloc_destroy(mem_ctx);
 
index cac54f8437f2fa609f80827f71a634025b068fa3..b2bd34bf71c6fd83c20d4ae2e18aa5dbdd899a46 100644 (file)
@@ -65,7 +65,7 @@ static WERROR reg_dir_open_key(REG_HANDLE *h, int hive, const char *name, REG_KE
        }
        closedir(d);
        ret = reg_key_new_abs(name, h, fullpath);
-       talloc_steal(mem_ctx, ret->mem_ctx, fullpath);
+       talloc_steal(ret->mem_ctx, fullpath);
        talloc_destroy(mem_ctx);
        *subkey = ret;
        return WERR_OK;
index c705a2e3cbd35614428fe6dc90cf7f2e0b131730..15a83197113d3455050be108b7dd3cad15657da5 100644 (file)
@@ -126,7 +126,7 @@ static WERROR gconf_fetch_values(REG_KEY *p, int *count, REG_VAL ***vals)
                } else newval->data_type = REG_NONE; 
 
                ar[(*count)] = newval;
-               ar = talloc_realloc(p->mem_ctx, ar, sizeof(REG_VAL *) * ((*count)+2));
+               ar = talloc_realloc(ar, sizeof(REG_VAL *) * ((*count)+2));
                (*count)++;
                g_free(cur->data);
                cur = cur->next;
@@ -151,7 +151,7 @@ static WERROR gconf_fetch_subkeys(REG_KEY *p, int *count, REG_KEY ***subs)
                ar[(*count)] = reg_key_new_abs(winpath, p->handle,NULL);
                free(winpath);
                ar[(*count)]->backend_data = reg_path_win2unix(talloc_strdup(ar[*count]->mem_ctx, cur->data));
-               ar = talloc_realloc_p(p->mem_ctx, ar, REG_KEY *, (*count)+2);
+               ar = talloc_realloc_p(ar, REG_KEY *, (*count)+2);
                (*count)++;
                g_free(cur->data);
                cur = cur->next;
index 9dfd3329e0c1040c5788b6a2b2873c03c14c5e11..fa7e22d010dabbaac43c8b5928c8ff660035edaa 100644 (file)
@@ -188,7 +188,7 @@ static WERROR ldb_open_key(REG_HANDLE *h, int num, const char *name, REG_KEY **k
        }
 
        *key = reg_key_new_abs(name, h, ldap_path);
-       talloc_steal(mem_ctx, (*key)->mem_ctx, ldap_path);
+       talloc_steal((*key)->mem_ctx, ldap_path);
        printf("Got something!\n");
        /* FIXME */
 
index 21c3bdac6e8615205912de35c979b673fb435584..8a67f83a7fa35c0c0df67d4482be42554ff59265 100644 (file)
@@ -1,8 +1,9 @@
 /* 
    Samba Unix SMB/CIFS implementation.
-   Samba temporary memory allocation functions
-   Copyright (C) Andrew Tridgell 2000-2004
-   Copyright (C) 2001, 2002 by Martin Pool <mbp@samba.org>
+
+   Samba temporary memory allocation functions - new interface
+
+   Copyright (C) Andrew Tridgell 2004
    
    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
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-/**
-   @defgroup talloc Simple memory allocator
-   @{
-   
-   This is a very simple temporary memory allocator. To use it do the following:
-
-   1) when you first want to allocate a pool of meomry use
-   talloc_init() and save the resulting context pointer somewhere
-
-   2) to allocate memory use talloc()
-
-   3) when _all_ of the memory allocated using this context is no longer needed
-   use talloc_destroy()
-
-   talloc does not zero the memory. 
-
-   @sa talloc.h
-*/
-
-/**
- * If you want testing for memory corruption use valgrind
- **/
-
 #include "includes.h"
 
 #define MAX_TALLOC_SIZE 0x10000000
-#define TALLOC_MAGIC 0x06052004
+#define TALLOC_MAGIC 0x14082004
 #define TALLOC_MAGIC_FREE 0x3421abcd
 
 struct talloc_chunk {
        struct talloc_chunk *next, *prev;
-       TALLOC_CTX *context;
+       struct talloc_chunk *parent, *child;
        size_t size;
-       void *ptr;
        uint_t magic;
+       char *name;
 };
 
 
-struct talloc_ctx {
-       struct talloc_chunk *list;
-       off_t total_alloc_size;
-
-       /** The name recorded for this pool, if any.  Should describe
-        * the purpose for which it was allocated.  The string is
-        * allocated within the pool. **/
-       char *name;
+/* 
+   Allocate a bit of memory as a child of an existing pointer
+*/
+void *talloc(void *context, size_t size)
+{
+       struct talloc_chunk *tc;
 
-       /** Pointer to the next allocate talloc pool, so that we can
-        * summarize all talloc memory usage. **/
-       struct talloc_ctx *next, *prev;
-};
+       if (size >= MAX_TALLOC_SIZE) {
+               return NULL;
+       }
 
+       tc = malloc(sizeof(*tc)+size);
+       if (tc == NULL) {
+               return NULL;
+       }
 
-/**
- * Start of linked list of all talloc pools.
- *
- * @todo We should turn the global list off when using Insure++,
- * otherwise all the memory will be seen as still reachable.
- **/
-static TALLOC_CTX *list_head;
+       tc->size = size;
+       tc->magic = TALLOC_MAGIC;
+       tc->child = NULL;
+       tc->name = NULL;
 
-/**
- * Add to the global list
- **/
-static void talloc_enroll(TALLOC_CTX *t)
-{
-#if 0
-       /* disabled enrole/disenrole until we have __thread support */
-       MUTEX_LOCK_BY_ID(MUTEX_TALLOC);
-       DLIST_ADD(list_head, t);
-       MUTEX_UNLOCK_BY_ID(MUTEX_TALLOC);
-#endif
-}
+       if (context) {
+               struct talloc_chunk *parent = ((struct talloc_chunk *)context)-1;
 
+               if (parent->magic != TALLOC_MAGIC) {
+                       DEBUG(0,("Bad magic in context - 0x%08x\n", parent->magic));
+                       free(tc);
+                       return NULL;
+               }
 
-static void talloc_disenroll(TALLOC_CTX *t)
-{
-#if 0
-       /* disabled enrole/disenrole until we have __thread support */
-       MUTEX_LOCK_BY_ID(MUTEX_TALLOC);
-       DLIST_REMOVE(list_head, t);
-       MUTEX_UNLOCK_BY_ID(MUTEX_TALLOC);
-#endif
-}
+               tc->parent = parent;
 
+               if (parent->child) {
+                       parent->child->parent = NULL;
+               }
 
-/** Create a new talloc context. **/
-static TALLOC_CTX *talloc_init_internal(void)
-{
-       TALLOC_CTX *t;
-
-       t = (TALLOC_CTX *)malloc(sizeof(TALLOC_CTX));
-       if (t) {
-               t->list = NULL;
-               t->total_alloc_size = 0;
-               t->name = NULL;
-               talloc_enroll(t);
+               DLIST_ADD(parent->child, tc);
+       } else {
+               tc->next = tc->prev = tc->parent = NULL;
        }
 
-       return t;
+       return (void *)(tc+1);
 }
 
 
-
-/**
- * Create a new talloc context, with a name specifying its purpose.
- **/
-
- TALLOC_CTX *talloc_init(char const *fmt, ...) 
+/*
+  create a named talloc pointer
+*/
+void *talloc_named(void *context, size_t size, 
+                  const char *fmt, ...) _PRINTF_ATTRIBUTE(3,4)
 {
-       TALLOC_CTX *t;
        va_list ap;
+       void *ptr;
+       struct talloc_chunk *tc;
 
-       t = talloc_init_internal();
-       if (t && fmt) {
-               /*
-                * t->name must not be talloced.
-                * as destroying the pool would destroy it. JRA.
-                */
-               t->name = NULL;
-               va_start(ap, fmt);
-               vasprintf(&t->name, fmt, ap);
-               va_end(ap);
-               if (!t->name) {
-                       talloc_destroy(t);
-                       t = NULL;
-               }
+       ptr = talloc(context, size);
+       if (ptr == NULL) {
+               return NULL;
        }
-       
-       return t;
-}
 
+       tc = ((struct talloc_chunk *)ptr)-1;
+
+       va_start(ap, fmt);
+       vasprintf(&tc->name, fmt, ap);
+       va_end(ap);
+
+       return ptr;
+}
 
 /*
-  return the talloc context given a pointer that has been allocated using
-  talloc
+  this is for compatibility with older versions of talloc
 */
-TALLOC_CTX *talloc_get_context(void *ptr)
+void *talloc_init(const char *fmt, ...) _PRINTF_ATTRIBUTE(1,2)
 {
+       va_list ap;
+       void *ptr;
        struct talloc_chunk *tc;
-       tc = ((struct talloc_chunk *)ptr)-1;
 
-       if (tc->magic == TALLOC_MAGIC) {
-               return tc->context;
-       } else {
+       ptr = talloc(NULL, 0);
+       if (ptr == NULL) {
                return NULL;
        }
+
+       tc = ((struct talloc_chunk *)ptr)-1;
+
+       va_start(ap, fmt);
+       vasprintf(&tc->name, fmt, ap);
+       va_end(ap);
+
+       return ptr;
 }
 
-/** Allocate a bit of memory from the specified pool **/
-void *talloc(TALLOC_CTX *t, size_t size)
+
+
+/* 
+   free a talloc pointer. This also frees all child pointers of this 
+   pointer recursively
+*/
+void talloc_free(void *ptr)
 {
        struct talloc_chunk *tc;
 
-       if (!t || size == 0) {
-               return NULL;
-       }
+       if (ptr == NULL) return;
 
-       tc = malloc(sizeof(*tc)+size);
-       if (!tc) {
-               return NULL;
+       tc = ((struct talloc_chunk *)ptr)-1;
+
+       if (tc->magic != TALLOC_MAGIC) {
+               DEBUG(0,("Bad talloc magic 0x%08x in talloc_free\n", tc->magic));
+               return;
        }
 
-       tc->context = t;
-       tc->size = size;
-       tc->magic = TALLOC_MAGIC;
+       while (tc->child) {
+               talloc_free(tc->child + 1);
+       }
 
-       DLIST_ADD(t->list, tc);
+       if (tc->parent) {
+               DLIST_REMOVE(tc->parent->child, tc);
+               if (tc->parent->child) {
+                       tc->parent->child->parent = tc->parent;
+               }
+       } else {
+               if (tc->prev) tc->prev->next = tc->next;
+               if (tc->next) tc->next->prev = tc->prev;
+       }
 
-       t->total_alloc_size += size;
+       tc->magic = TALLOC_MAGIC_FREE;
+       if (tc->name) free(tc->name);
 
-       return (void *)(tc+1);
+       free(tc);
 }
 
-/** A talloc version of realloc */
-void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size)
+
+
+/*
+  A talloc version of realloc 
+*/
+void *talloc_realloc(void *ptr, size_t size)
 {
        struct talloc_chunk *tc;
        void *new_ptr;
 
        /* size zero is equivalent to free() */
-       if (!t) {
-               return NULL;
-       }
-
        if (size == 0) {
-               talloc_free(t, ptr);
+               talloc_free(ptr);
                return NULL;
        }
 
        /* realloc(NULL) is equavalent to malloc() */
        if (ptr == NULL) {
-               return talloc(t, size);
+               return talloc(NULL, size);
        }
 
        tc = ((struct talloc_chunk *)ptr)-1;
 
-       if (tc->context != t) {
-               DEBUG(0,("Bad talloc context passed to talloc_realloc\n"));
-               return NULL;
-       }
-
        if (tc->magic != TALLOC_MAGIC) {
                DEBUG(0,("Bad talloc magic 0x%08x in talloc_realloc\n", tc->magic));
                return NULL;
@@ -235,11 +203,11 @@ void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size)
                return NULL;
        }
 
-       if (tc == t->list) {
-               t->list = new_ptr;
-       }
        tc = new_ptr;
        tc->magic = TALLOC_MAGIC;
+       if (tc->parent) {
+               tc->parent->child = new_ptr;
+       }
 
        if (tc->prev) {
                tc->prev->next = tc;
@@ -248,129 +216,74 @@ void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size)
                tc->next->prev = tc;
        }
 
-       t->total_alloc_size += (size - tc->size);
        tc->size = size;
 
        return (void *)(tc+1);
 }
 
 /* 
-   free a lump from a pool. Use sparingly please.
+   move a lump of memory from one talloc context to another return the
+   ptr on success, or NUL if it could not be transferred
 */
-void talloc_free(TALLOC_CTX *ctx, void *ptr)
+void *talloc_steal(void *new_ctx, void *ptr)
 {
-       struct talloc_chunk *tc;
-
-       if (!ptr || !ctx->list) return;
-
-       tc = ((struct talloc_chunk *)ptr)-1;
-
-       if (tc->context != ctx) {
-               DEBUG(0,("Bad talloc context passed to talloc_free\n"));
-       }
-
-       if (tc->magic != TALLOC_MAGIC) {
-               DEBUG(0,("Bad talloc magic 0x%08x in talloc_free\n", tc->magic));
-       }
-
-       DLIST_REMOVE(ctx->list, tc);
-
-       ctx->total_alloc_size -= tc->size;
-       tc->magic = TALLOC_MAGIC_FREE;
-
-       free(tc);
-}
-
-
-/* 
-   move a lump of memory from one talloc context to another
-   return the ptr on success, or NULL if it could not be found
-   in the old context or could not be transferred
-*/
-void *talloc_steal(TALLOC_CTX *old_ctx, TALLOC_CTX *new_ctx, void *ptr)
-{
-       struct talloc_chunk *tc;
+       struct talloc_chunk *tc, *new_tc;
 
        if (!ptr) {
                return NULL;
        }
 
        tc = ((struct talloc_chunk *)ptr)-1;
-
-       if (tc->context != old_ctx) {
-               DEBUG(0,("Bad talloc context passed to talloc_steal\n"));
-               return NULL;
-       }
+       new_tc = ((struct talloc_chunk *)new_ctx)-1;
 
        if (tc->magic != TALLOC_MAGIC) {
                DEBUG(0,("Bad talloc magic 0x%08x in talloc_steal\n", tc->magic));
                return NULL;
        }
-
-       DLIST_REMOVE(old_ctx->list, tc);
-       DLIST_ADD(new_ctx->list, tc);
-
-       tc->context = new_ctx;
-
-       old_ctx->total_alloc_size -= tc->size;
-       new_ctx->total_alloc_size += tc->size;
-       
-       return ptr;
-}
-
-
-
-/** Destroy all the memory allocated inside @p t, but not @p t
- * itself. */
-void talloc_destroy_pool(TALLOC_CTX *t)
-{
-       if (!t) {
-               return;
+       if (new_tc->magic != TALLOC_MAGIC) {
+               DEBUG(0,("Bad new talloc magic 0x%08x in talloc_steal\n", new_tc->magic));
+               return NULL;
        }
 
-       while (t->list) {
-               struct talloc_chunk *tc = t->list;
-               if (tc->magic != TALLOC_MAGIC) {
-                       DEBUG(0,("Bad magic 0x%08x in talloc_destroy_pool\n", 
-                                tc->magic));
-                       return;
+       if (tc->parent) {
+               DLIST_REMOVE(tc->parent->child, tc);
+               if (tc->parent->child) {
+                       tc->parent->child->parent = tc->parent;
                }
-               DLIST_REMOVE(t->list, tc);
-               tc->magic = TALLOC_MAGIC_FREE;
-               free(tc);
+       } else {
+               if (tc->prev) tc->prev->next = tc->next;
+               if (tc->next) tc->next->prev = tc->prev;
        }
 
-       t->total_alloc_size = 0;
-}
-
-/** Destroy a whole pool including the context */
-void talloc_destroy(TALLOC_CTX *t)
-{
-       if (!t)
-               return;
+       tc->parent = new_tc;
+       if (new_tc->child) new_tc->child->parent = NULL;
+       DLIST_ADD(new_tc->child, tc);
 
-       talloc_destroy_pool(t);
-       talloc_disenroll(t);
-       SAFE_FREE(t->name);
-       SAFE_FREE(t);
+       return ptr;
 }
 
-/** Return the current total size of the pool. */
-size_t talloc_pool_size(TALLOC_CTX *t)
+/*
+  return the total size of a talloc pool (subtree)
+*/
+off_t talloc_total_size(void *p)
 {
-       return t->total_alloc_size;
-}
+       off_t total = 0;
+       struct talloc_chunk *c, *tc;
 
-const char *talloc_pool_name(TALLOC_CTX const *t)
-{
-       if (t) return t->name;
+       tc = ((struct talloc_chunk *)p)-1;
 
-       return NULL;
+       total = tc->size;
+       for (c=tc->child;c;c=c->next) {
+               total += talloc_total_size(c+1);
+       }
+       return total;
 }
 
 
-/** talloc and zero memory. */
-void *talloc_zero(TALLOC_CTX *t, size_t size)
+/* 
+   talloc and zero memory. 
+*/
+void *talloc_zero(void *t, size_t size)
 {
        void *p = talloc(t, size);
 
@@ -382,8 +295,10 @@ void *talloc_zero(TALLOC_CTX *t, size_t size)
 }
 
 
-/** memdup with a talloc. */
-void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size)
+/*
+  memdup with a talloc. 
+*/
+void *talloc_memdup(void *t, const void *p, size_t size)
 {
        void *newp = talloc(t,size);
 
@@ -394,8 +309,10 @@ void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size)
        return newp;
 }
 
-/** strdup with a talloc */
-char *talloc_strdup(TALLOC_CTX *t, const char *p)
+/*
+  strdup with a talloc 
+*/
+char *talloc_strdup(void *t, const char *p)
 {
        if (!p) {
                return NULL;
@@ -403,8 +320,10 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p)
        return talloc_memdup(t, p, strlen(p) + 1);
 }
 
-/** strndup with a talloc */
-char *talloc_strndup(TALLOC_CTX *t, const char *p, size_t n)
+/*
+  strndup with a talloc 
+*/
+char *talloc_strndup(void *t, const char *p, size_t n)
 {
        size_t len = strnlen(p, n);
        char *ret;
@@ -416,23 +335,7 @@ char *talloc_strndup(TALLOC_CTX *t, const char *p, size_t n)
        return ret;
 }
 
-/**
- * Perform string formatting, and return a pointer to newly allocated
- * memory holding the result, inside a memory pool.
- **/
- char *talloc_asprintf(TALLOC_CTX *t, const char *fmt, ...)
-{
-       va_list ap;
-       char *ret;
-
-       va_start(ap, fmt);
-       ret = talloc_vasprintf(t, fmt, ap);
-       va_end(ap);
-       return ret;
-}
-
-
- char *talloc_vasprintf(TALLOC_CTX *t, const char *fmt, va_list ap)
+ char *talloc_vasprintf(void *t, const char *fmt, va_list ap)
 {      
        int len;
        char *ret;
@@ -452,31 +355,29 @@ char *talloc_strndup(TALLOC_CTX *t, const char *p, size_t n)
 }
 
 
-/**
- * Realloc @p s to append the formatted result of @p fmt and return @p
- * s, which may have moved.  Good for gradually accumulating output
- * into a string buffer.
- **/
- char *talloc_asprintf_append(TALLOC_CTX *t, char *s,
-                             const char *fmt, ...)
+/*
+  Perform string formatting, and return a pointer to newly allocated
+  memory holding the result, inside a memory pool.
+ */
+char *talloc_asprintf(void *t, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3)
 {
        va_list ap;
+       char *ret;
 
        va_start(ap, fmt);
-       s = talloc_vasprintf_append(t, s, fmt, ap);
+       ret = talloc_vasprintf(t, fmt, ap);
        va_end(ap);
-       return s;
+       return ret;
 }
 
 
-
 /**
  * Realloc @p s to append the formatted result of @p fmt and @p ap,
  * and return @p s, which may have moved.  Good for gradually
  * accumulating output into a string buffer.
  **/
- char *talloc_vasprintf_append(TALLOC_CTX *t, char *s,
-                              const char *fmt, va_list ap)
+char *talloc_vasprintf_append(char *s,
+                             const char *fmt, va_list ap)
 {      
        int len, s_len;
        va_list ap2;
@@ -486,11 +387,11 @@ char *talloc_strndup(TALLOC_CTX *t, const char *p, size_t n)
        if (s) {
                s_len = strlen(s);
        } else {
-               s = 0;
+               s_len = 0;
        }
        len = vsnprintf(NULL, 0, fmt, ap2);
 
-       s = talloc_realloc(t, s, s_len + len+1);
+       s = talloc_realloc(s, s_len + len+1);
        if (!s) return NULL;
 
        VA_COPY(ap2, ap);
@@ -500,109 +401,45 @@ char *talloc_strndup(TALLOC_CTX *t, const char *p, size_t n)
        return s;
 }
 
-
-/**
- * Return a human-readable description of all talloc memory usage.
- * The result is allocated from @p t.
- **/
-char *talloc_describe_all(TALLOC_CTX *rt)
+/*
+  Realloc @p s to append the formatted result of @p fmt and return @p
+  s, which may have moved.  Good for gradually accumulating output
+  into a string buffer.
+ */
+char *talloc_asprintf_append(char *s,
+                            const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3)
 {
-       int n_pools = 0, total_chunks = 0;
-       size_t total_bytes = 0;
-       TALLOC_CTX *it;
-       char *s;
-
-       if (!rt) return NULL;
-
-       s = talloc_asprintf(rt, "global talloc allocations in pid: %u\n",
-                           (uint_t) getpid());
-       s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
-                                  "name", "chunks", "bytes");
-       s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
-                                  "----------------------------------------",
-                                  "--------",
-                                  "--------"); 
-       MUTEX_LOCK_BY_ID(MUTEX_TALLOC);
-       
-       for (it = list_head; it; it = it->next) {
-               size_t bytes;
-               int n_chunks;
-               fstring what;
-               
-               n_pools++;
-               
-               talloc_get_allocation(it, &bytes, &n_chunks);
-
-               if (it->name)
-                       fstrcpy(what, it->name);
-               else
-                       slprintf(what, sizeof(what), "@%p", it);
-               
-               s = talloc_asprintf_append(rt, s, "%-40s %8u %8u\n",
-                                          what,
-                                          (uint_t) n_chunks,
-                                          (uint_t) bytes);
-               total_bytes += bytes;
-               total_chunks += n_chunks;
-       }
-
-       MUTEX_UNLOCK_BY_ID(MUTEX_TALLOC);
-
-       s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
-                                  "----------------------------------------",
-                                  "--------",
-                                  "--------"); 
-
-       s = talloc_asprintf_append(rt, s, "%-40s %8u %8u\n",
-                                  "TOTAL",
-                                  (uint_t) total_chunks, (uint_t) total_bytes);
+       va_list ap;
 
+       va_start(ap, fmt);
+       s = talloc_vasprintf_append(s, fmt, ap);
+       va_end(ap);
        return s;
 }
 
-
-
-/**
- * Return an estimated memory usage for the specified pool.  This does
- * not include memory used by the underlying malloc implementation.
- **/
-void talloc_get_allocation(TALLOC_CTX *t,
-                          size_t *total_bytes,
-                          int *n_chunks)
-{
-       struct talloc_chunk *tc;
-
-       if (t) {
-               *total_bytes = 0;
-               *n_chunks = 0;
-
-               for (tc = t->list; tc; tc = tc->next) {
-                       n_chunks[0]++;
-                       *total_bytes += tc->size;
-               }
-       }
-}
-
 /*
-  realloc an array, checking for integer overflow in the array size
+  alloc an array, checking for integer overflow in the array size
 */
-void *talloc_realloc_array(TALLOC_CTX *ctx, void *ptr, size_t el_size, uint_t count)
+void *talloc_array(void *ctx, size_t el_size, uint_t count)
 {
        if (count == 0 ||
            count >= MAX_TALLOC_SIZE/el_size) {
                return NULL;
        }
-       return talloc_realloc(ctx, ptr, el_size * count);
+       return talloc(ctx, el_size * count);
 }
 
 
 /*
-  we really should get rid of this
+  realloc an array, checking for integer overflow in the array size
 */
-void *talloc_strdup_w(TALLOC_CTX *mem_ctx, void *s)
+void *talloc_realloc_array(void *ptr, size_t el_size, uint_t count)
 {
-       size_t len = strlen_w(s);
-       return talloc_memdup(mem_ctx, s, (len+1)*2);
+       if (count == 0 ||
+           count >= MAX_TALLOC_SIZE/el_size) {
+               return NULL;
+       }
+       return talloc_realloc(ptr, el_size * count);
 }
 
 /*
@@ -610,8 +447,12 @@ void *talloc_strdup_w(TALLOC_CTX *mem_ctx, void *s)
 */
 void *talloc_ldb_alloc(void *context, void *ptr, size_t size)
 {
-       return talloc_realloc((TALLOC_CTX *)context, ptr, size);
+       if (ptr == NULL) {
+               return talloc(context, size);
+       }
+       if (size == 0) {
+               talloc_free(ptr);
+               return NULL;
+       }
+       return talloc_realloc(ptr, size);
 }
-
-
-/** @} */
index bbe1ee60a46b152d129a66512c18884b63c025f3..22870a934a7f6c629c92f5a1c0369307374c15d8 100644 (file)
 void msg_pool_usage(int msg_type, pid_t src_pid,
                    void *UNUSED(buf), size_t UNUSED(len))
 {
-       char *reply;
+       const char *reply="NOT IMPLEMENTED\n";
        TALLOC_CTX *reply_pool = talloc_init("msg_pool_usage");
 
        SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
        
        DEBUG(2,("Got POOL_USAGE\n"));
 
+#if 0
        reply = talloc_describe_all(reply_pool);
-       
+#endif
        message_send_pid(src_pid, MSG_POOL_USAGE,
                         reply, strlen(reply)+1, True);
 
index a6f54f9a8d9293ab703b64bd325ad0fe58b56246..a66a363c177e8ccb1cbe2f1c9a28288c6055fbfc 100644 (file)
@@ -1452,7 +1452,7 @@ BOOL add_string_to_array(TALLOC_CTX *mem_ctx,
 {
        char *dup_str = talloc_strdup(mem_ctx, str);
 
-       *strings = talloc_realloc(mem_ctx, *strings,
+       *strings = talloc_realloc(*strings,
                                  ((*num)+1) * sizeof(**strings));
 
        if ((*strings == NULL) || (dup_str == NULL))
index 09a1c9a4df9857a094b76149c1a52dfb6a468b26..2bd990836ee0bfaa8dd44f8629712514d2dc3d71 100644 (file)
@@ -249,14 +249,6 @@ const smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c)
        return NULL;
 }
 
-static int strncmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len)
-{
-       size_t n = 0;
-       while ((n < len) && *b && *a == *b) { a++; b++; n++;}
-       return (len - n)?(*a - *b):0;   
-}
-
-
 /*******************************************************************
  Convert a string to lower case.
  return True if any char is converted
index 156f20e53eb670152c2681b1ffae20e4cb9ab616..a11b7bd3ed378a79d4368fc9ead9dfe87abfe9b1 100644 (file)
@@ -24,7 +24,7 @@
 
 void uuid_generate_random(struct GUID *out)
 {
-       generate_random_buffer(out, sizeof(struct GUID));
+       generate_random_buffer((unsigned char *)out, sizeof(struct GUID));
        out->clock_seq[0] = (out->clock_seq[0] & 0x3F) | 0x80;
        out->time_hi_and_version = (out->time_hi_and_version & 0x0FFF) | 0x4000;
 }
index f038b23d23dbb457eb11012bedf00918e4fa92a3..8992cb9dcf331b40514c9124161e947417a67ccc 100644 (file)
@@ -795,7 +795,7 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods,
        for (curmod=0; modlist[curmod] && modlist[curmod] != (LDAPMod *) -1;
             curmod++);
        if (modlist[curmod] == (LDAPMod *) -1) {
-               if (!(modlist = talloc_realloc(ctx, modlist, 
+               if (!(modlist = talloc_realloc(modlist, 
                        (curmod+ADS_MODLIST_ALLOC_SIZE+1)*sizeof(LDAPMod *))))
                        return ADS_ERROR(LDAP_NO_MEMORY);
                memset(&modlist[curmod], 0, 
@@ -1703,7 +1703,7 @@ char **ads_pull_strings_range(ADS_STRUCT *ads,
                return NULL;
        }
 
-       strings = talloc_realloc(mem_ctx, current_strings,
+       strings = talloc_realloc(current_strings,
                                 sizeof(*current_strings) *
                                 (*num_strings + num_new_strings));
        
index e2c267cc965f5c97a9a15c2ced8473d0c2fb5de6..0e2cdabc0aebcc782137e189f53860a814177faa 100644 (file)
@@ -83,8 +83,8 @@ static BOOL smbcli_list_new_callback(void *private, union smb_search_data *file)
        file_info *tdl;
  
        /* add file info to the dirlist pool */
-       tdl = talloc_realloc(state->mem_ctx, state->dirlist,
-                       state->dirlist_len + sizeof(struct file_info));
+       tdl = talloc_realloc(state->dirlist,
+                            state->dirlist_len + sizeof(struct file_info));
 
        if (!tdl) {
                return False;
@@ -225,8 +225,8 @@ static BOOL smbcli_list_old_callback(void *private, union smb_search_data *file)
        file_info *tdl;
        
        /* add file info to the dirlist pool */
-       tdl = talloc_realloc(state->mem_ctx, state->dirlist,
-                       state->dirlist_len + sizeof(struct file_info));
+       tdl = talloc_realloc(state->dirlist,
+                            state->dirlist_len + sizeof(struct file_info));
 
        if (!tdl) {
                return False;
index 123def94169039bd53535b5e619d13a7d928746b..7e60e48293e30fddccb16d5465c5d394550bc100 100644 (file)
@@ -179,7 +179,7 @@ static struct ldap_parse_tree *ldap_parse_filterlist(TALLOC_CTX *mem_ctx,
 
        while (*s && (next = ldap_parse_filter(mem_ctx, &s))) {
                struct ldap_parse_tree **e;
-               e = talloc_realloc(mem_ctx, ret->u.list.elements,
+               e = talloc_realloc(ret->u.list.elements,
                                   sizeof(struct ldap_parse_tree) *
                                   (ret->u.list.num_elements+1));
                if (!e) {
index 2f23dd16a6054affbdc69e110690c88ae3be6eb7..2ec3b827ceb188051d07de61349cbaccba8d0cbc 100644 (file)
@@ -51,7 +51,7 @@ static char *next_chunk(TALLOC_CTX *mem_ctx,
                if (chunk_size+1 >= alloc_size) {
                        char *c2;
                        alloc_size += 1024;
-                       c2 = talloc_realloc(mem_ctx, chunk, alloc_size);
+                       c2 = talloc_realloc(chunk, alloc_size);
                        if (!c2) {
                                errno = ENOMEM;
                                return NULL;
@@ -158,7 +158,7 @@ static int next_attr(char **s, const char **attr, struct ldap_val *value)
 BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldap_val *value,
                                struct ldap_attribute *attrib)
 {
-       attrib->values = talloc_realloc(mem_ctx, attrib->values,
+       attrib->values = talloc_realloc(attrib->values,
                                        sizeof(*attrib->values) *
                                        (attrib->num_values+1));
        if (attrib->values == NULL)
@@ -175,7 +175,7 @@ BOOL add_attrib_to_array_talloc(TALLOC_CTX *mem_ctx,
                                       struct ldap_attribute **attribs,
                                       int *num_attribs)
 {
-       *attribs = talloc_realloc(mem_ctx, *attribs,
+       *attribs = talloc_realloc(*attribs,
                                  sizeof(**attribs) * (*num_attribs+1));
 
        if (*attribs == NULL)
@@ -207,8 +207,7 @@ static BOOL fill_add_attributes(struct ldap_message *msg, char **chunk)
                }
 
                if (attrib == NULL) {
-                       r->attributes = talloc_realloc(msg->mem_ctx,
-                                                      r->attributes,
+                       r->attributes = talloc_realloc(r->attributes,
                                                       sizeof(*r->attributes) *
                                                       (r->num_attributes+1));
                        if (r->attributes == NULL)
@@ -232,7 +231,7 @@ BOOL add_mod_to_array_talloc(TALLOC_CTX *mem_ctx,
                                    struct ldap_mod **mods,
                                    int *num_mods)
 {
-       *mods = talloc_realloc(mem_ctx, *mods,
+       *mods = talloc_realloc(*mods,
                               sizeof(**mods) * ((*num_mods)+1));
 
        if (*mods == NULL)
index f46c23837894d258999f2c6648d010ecdfcb0149..0ee631a549f85c2de9001392c33b5c2852562b00 100644 (file)
@@ -69,7 +69,7 @@ void smbcli_session_close(struct smbcli_session *session)
 ****************************************************************************/
 struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session, union smb_sesssetup *parms) 
 {
-       struct smbcli_request *req;
+       struct smbcli_request *req = NULL;
 
        switch (parms->generic.level) {
        case RAW_SESSSETUP_GENERIC:
index 343904999a4d58b793b1620d14c55cba7e2f20fc..2bb50d200f3c3be8d31d3256199358810e1ea064 100644 (file)
@@ -181,7 +181,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in
        ret = smbcli_sock_connect(sock, &ip, port);
 
        if (ret) {
-               sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name);
+               sock->hostname = talloc_steal(sock->mem_ctx, name);
        }
 
        talloc_destroy(mem_ctx);
index 91f0f0f8f51a06eea34fc68e24107f18314013b3..82939467ae7529d4aba3251cad426ff038cc8caa 100644 (file)
@@ -296,7 +296,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport)
 {
        uint8_t *buffer, *hdr, *vwv;
        int len;
-       uint16_t wct, mid = 0;
+       uint16_t wct=0, mid = 0;
        struct smbcli_request *req;
 
        buffer = transport->recv_buffer.buffer;
@@ -309,7 +309,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport)
 
        /* see if it could be an oplock break request */
        if (handle_oplock_break(transport, len, hdr, vwv)) {
-               talloc_free(transport->mem_ctx, buffer);
+               talloc_free(buffer);
                return;
        }
 
@@ -325,7 +325,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport)
                if (!req) goto error;
 
                req->in.buffer = buffer;
-               talloc_steal(transport->mem_ctx, req->mem_ctx, buffer);
+               talloc_steal(req->mem_ctx, buffer);
                req->in.size = len;
                req->in.allocated = req->in.size;
                goto async;
@@ -349,7 +349,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport)
 
        /* fill in the 'in' portion of the matching request */
        req->in.buffer = buffer;
-       talloc_steal(transport->mem_ctx, req->mem_ctx, buffer);
+       talloc_steal(req->mem_ctx, buffer);
        req->in.size = len;
        req->in.allocated = req->in.size;
 
index 97c0910451507dd000c4fd0f97855bfed287594c..57e322da322712ff0e71019ecdc42631a16cecf6 100644 (file)
@@ -70,7 +70,7 @@ void smbcli_tree_close(struct smbcli_tree *tree)
 ****************************************************************************/
 struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb_tcon *parms)
 {
-       struct smbcli_request *req;
+       struct smbcli_request *req = NULL;
 
        switch (parms->tcon.level) {
        case RAW_TCON_TCON:
index e07fbcd2884d0452f6ac6eedaf9be993078ace08..d78f10fe1a512e739ac2dc6b1285c446afc72bf5 100644 (file)
@@ -128,7 +128,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob,
                blob2.data = blob->data + ofs;
                blob2.length = ea_size - ofs;
 
-               *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1));
+               *eas = talloc_realloc(*eas, sizeof(**eas) * (n+1));
                if (! *eas) return NT_STATUS_NO_MEMORY;
 
                len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]);
index 8bd8e5d8af209d5f1b1c714d635eaf48f3251ed5..1b858d489a57d829754f78e77e88d3c432d7c76c 100644 (file)
@@ -34,7 +34,7 @@
 struct smbcli_request *smb_raw_rename_send(struct smbcli_tree *tree,
                                        union smb_rename *parms)
 {
-       struct smbcli_request *req; 
+       struct smbcli_request *req = NULL
 
        switch (parms->generic.level) {
        case RAW_RENAME_RENAME:
@@ -490,7 +490,7 @@ NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_o
 ****************************************************************************/
 struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms)
 {
-       struct smbcli_request *req; 
+       struct smbcli_request *req = NULL
 
        switch (parms->generic.level) {
        case RAW_CLOSE_GENERIC:
@@ -536,7 +536,7 @@ NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms)
 ****************************************************************************/
 struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_lock *parms)
 {
-       struct smbcli_request *req; 
+       struct smbcli_request *req = NULL
 
        switch (parms->generic.level) {
        case RAW_LOCK_GENERIC:
index 9b82bf6fa09acb5a8cf1d79c0e758b3c4db641ea..aac8f2657bf2582659682b5e910247a48f805f8f 100644 (file)
@@ -174,7 +174,7 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session,
                while (blob->length - ofs >= 24) {
                        uint_t n = parms->stream_info.out.num_streams;
                        parms->stream_info.out.streams = 
-                               talloc_realloc(mem_ctx,parms->stream_info.out.streams,
+                               talloc_realloc(parms->stream_info.out.streams,
                                               (n+1) * sizeof(parms->stream_info.out.streams[0]));
                        if (!parms->stream_info.out.streams) {
                                return NT_STATUS_NO_MEMORY;
index f0a9a063edf7631ab3e514c66520cba42f53172a..dbca6fb7a54ec998d363dde35e6634cac3d94472 100644 (file)
@@ -33,7 +33,7 @@
 struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms)
 {
        BOOL bigoffset = False;
-       struct smbcli_request *req; 
+       struct smbcli_request *req = NULL
 
        switch (parms->generic.level) {
        case RAW_READ_GENERIC:
@@ -185,7 +185,7 @@ NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms)
 struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms)
 {
        BOOL bigoffset = False;
-       struct smbcli_request *req; 
+       struct smbcli_request *req = NULL
 
        switch (parms->generic.level) {
        case RAW_WRITE_GENERIC:
index bc87af4297d17089e319a0c7ad7511f8ba8a1257..20a389af4c20b3fc2dd3fc15ffa46f2a64f27dc7 100644 (file)
@@ -224,7 +224,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si
 
        /* we need to realloc */
        req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION;
-       buf2 = talloc_realloc(req->mem_ctx, req->out.buffer, req->out.allocated);
+       buf2 = talloc_realloc(req->out.buffer, req->out.allocated);
        if (buf2 == NULL) {
                smb_panic("out of memory in req_grow_allocation");
        }
@@ -915,7 +915,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session,
 
        max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR;         
 
-       blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len);
+       blob->data = talloc_realloc(blob->data, blob->length + max_len);
        if (!blob->data) {
                return 0;
        }
index 53f8075822a6b6920e696cf3b086efb5f7b0b094..49b43dd9302b7d082b1100ac3b6a2ca74a1cf08e 100644 (file)
@@ -84,7 +84,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req,
 
        /* allocate it */
        if (total_data != 0) {
-               tdata = talloc_realloc(mem_ctx, parms->out.data.data,total_data);
+               tdata = talloc_realloc(parms->out.data.data,total_data);
                if (!tdata) {
                        DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data));
                        req->status = NT_STATUS_NO_MEMORY;
@@ -94,7 +94,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req,
        }
 
        if (total_param != 0) {
-               tparam = talloc_realloc(mem_ctx, parms->out.params.data,total_param);
+               tparam = talloc_realloc(parms->out.params.data,total_param);
                if (!tparam) {
                        DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param));
                        req->status = NT_STATUS_NO_MEMORY;
index 1d50d95afa6d1f8613f29914a79d46804ab99f76..cbb1046281c8e21853f3d56374496caaf8296ca5 100644 (file)
@@ -188,7 +188,7 @@ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t size)
        if (size > ndr->alloc_size) {
                ndr->alloc_size = size;
        }
-       ndr->data = talloc_realloc(ndr->mem_ctx, ndr->data, ndr->alloc_size);
+       ndr->data = talloc_realloc(ndr->data, ndr->alloc_size);
        if (!ndr->data) {
                return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
                                      ndr->alloc_size);
index 438a9a4cf3683ac6faf1972a42bc138ec0f47eb7..0e8828acbdaac532f4ef750ea5e29c9e43b39f9f 100644 (file)
@@ -660,8 +660,7 @@ NTSTATUS dcerpc_request(struct dcerpc_pipe *p,
 
                length = pkt.u.response.stub_and_verifier.length;
 
-               payload.data = talloc_realloc(mem_ctx, 
-                                             payload.data, 
+               payload.data = talloc_realloc(payload.data, 
                                              payload.length + length);
                if (!payload.data) {
                        return NT_STATUS_NO_MEMORY;
index 51722c8a04e6c9158dba3fd079266dbdfaf0547b..d3a0a42d10e4f5eb2b01e513b8fafffa37048798 100644 (file)
@@ -98,7 +98,7 @@ static NTSTATUS dcerpc_raw_recv(struct dcerpc_pipe *p,
        }
 
        /* make sure the payload can hold the whole fragment */
-       payload.data = talloc_realloc(mem_ctx, payload.data, frag_length);
+       payload.data = talloc_realloc(payload.data, frag_length);
        if (!payload.data) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -203,7 +203,7 @@ static NTSTATUS smb_secondary_request(struct dcerpc_pipe *p,
                return status;
        }
 
-       blob->data = talloc_realloc(mem_ctx, blob->data, frag_length);
+       blob->data = talloc_realloc(blob->data, frag_length);
        if (!blob->data) {
                return NT_STATUS_NO_MEMORY;
        }
index d2cd0b38d57381f5df34672a930bba46927b3b6d..347ff39d974e7b40c43e8edb85e42714eddd47cb 100644 (file)
@@ -178,7 +178,7 @@ static NTSTATUS rap_push_string(struct ndr_push *data_push,
        NDR_CHECK(ndr_push_uint16(data_push, heap->offset));
        NDR_CHECK(ndr_push_uint16(data_push, 0));
 
-       heap->strings = talloc_realloc(heap->mem_ctx, heap->strings,
+       heap->strings = talloc_realloc(heap->strings,
                                       sizeof(*heap->strings) *
                                       (heap->num_strings + 1));
 
index e2210869501b4f96d9a0aa168f372185123b273c..8be80183c596d69ad0a3c6d18c5eac02fc33527b 100644 (file)
@@ -104,7 +104,7 @@ struct svfs_dir *svfs_list(TALLOC_CTX *mem_ctx, struct smbsrv_request *req, cons
                
                if (dir->count >= allocated) {
                        allocated = (allocated + 100) * 1.2;
-                       dir->files = talloc_realloc(mem_ctx, dir->files, allocated * sizeof(dir->files[0]));
+                       dir->files = talloc_realloc(dir->files, allocated * sizeof(dir->files[0]));
                        if (!dir->files) { 
                                closedir(odir);
                                return NULL;
index 7da9667e3c8e211de403cf7602c5736426afe297..1949ecb23553361a5ae310784d1fc08abfe9437a 100644 (file)
@@ -105,7 +105,7 @@ struct svfs_dir *svfs_list_unix(TALLOC_CTX *mem_ctx, struct smbsrv_request *req,
                
                if (dir->count >= allocated) {
                        allocated = (allocated + 100) * 1.2;
-                       dir->files = talloc_realloc(mem_ctx, dir->files, allocated * sizeof(dir->files[0]));
+                       dir->files = talloc_realloc(dir->files, allocated * sizeof(dir->files[0]));
                        if (!dir->files) { 
                                closedir(odir);
                                return NULL;
index ad889daf36d4f4ac0eb229a69db92af978af706c..ae64c96c755087fa78d1c8403c50865b0ab7f407 100644 (file)
@@ -580,8 +580,8 @@ static NTSTATUS svfs_close(struct smbsrv_request *req, union smb_close *io)
        }
 
        DLIST_REMOVE(private->open_files, f);
-       talloc_free(req->tcon->mem_ctx, f->name);
-       talloc_free(req->tcon->mem_ctx, f);
+       talloc_free(f->name);
+       talloc_free(f);
 
        return NT_STATUS_OK;
 }
@@ -766,7 +766,7 @@ static NTSTATUS svfs_search_first(struct smbsrv_request *req, union smb_search_f
 
        dir = svfs_list(mem_ctx, req, io->t2ffirst.in.pattern);
        if (!dir) {
-               talloc_destroy_pool(mem_ctx);
+               talloc_free(mem_ctx);
                return NT_STATUS_FOOBAR;
        }
 
index f83916f3c9d07fe00c6836c8837d9cfab4eb9e75..ab61ba3911484921499db95a3ab1d9b2b5757ed2 100644 (file)
@@ -734,7 +734,7 @@ NTSTATUS dcesrv_input_process(struct dcesrv_connection *dce_conn)
        }
        call = talloc_p(mem_ctx, struct dcesrv_call_state);
        if (!call) {
-               talloc_free(dce_conn->mem_ctx, dce_conn->partial_input.data);
+               talloc_free(dce_conn->partial_input.data);
                talloc_destroy(mem_ctx);
                return NT_STATUS_NO_MEMORY;
        }
@@ -747,7 +747,7 @@ NTSTATUS dcesrv_input_process(struct dcesrv_connection *dce_conn)
 
        ndr = ndr_pull_init_blob(&blob, mem_ctx);
        if (!ndr) {
-               talloc_free(dce_conn->mem_ctx, dce_conn->partial_input.data);
+               talloc_free(dce_conn->partial_input.data);
                talloc_destroy(mem_ctx);
                return NT_STATUS_NO_MEMORY;
        }
@@ -758,7 +758,7 @@ NTSTATUS dcesrv_input_process(struct dcesrv_connection *dce_conn)
 
        status = ndr_pull_dcerpc_packet(ndr, NDR_SCALARS|NDR_BUFFERS, &call->pkt);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(dce_conn->mem_ctx, dce_conn->partial_input.data);
+               talloc_free(dce_conn->partial_input.data);
                talloc_destroy(mem_ctx);
                return status;
        }
@@ -801,8 +801,7 @@ NTSTATUS dcesrv_input_process(struct dcesrv_connection *dce_conn)
                }
 
                call->pkt.u.request.stub_and_verifier.data = 
-                       talloc_realloc(call->mem_ctx,
-                                      call->pkt.u.request.stub_and_verifier.data, alloc_size);
+                       talloc_realloc(call->pkt.u.request.stub_and_verifier.data, alloc_size);
                if (!call->pkt.u.request.stub_and_verifier.data) {
                        return dcesrv_fault(call2, DCERPC_FAULT_OTHER);
                }
index f2c7b7833509b3872d37f3b528693a6426c53e68..62c545cd941b517c1ef98fd3c627417b38121ec0 100644 (file)
@@ -129,7 +129,7 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
                struct dcesrv_if_list *iface;
 
                for (iface=d->interface_list;iface;iface=iface->next) {
-                       (*eps) = talloc_realloc_p(mem_ctx, *eps, 
+                       (*eps) = talloc_realloc_p(*eps, 
                                                  struct dcesrv_ep_iface,
                                                  total + 1);
                        if (!*eps) {
index a4ef06128cc60d1e0ab08b52790700dbcd08a10d..d01c0c577b03554c40b1e6f4adbf8dc7ddbf091a 100644 (file)
@@ -265,14 +265,14 @@ static NTSTATUS netr_ServerAuthenticate3(struct dcesrv_call_state *dce_call, TAL
 
        if (pipe_state->account_name) {
                /* We don't want a memory leak on this long-lived talloc context */
-               talloc_free(pipe_state->mem_ctx, pipe_state->account_name);
+               talloc_free(pipe_state->account_name);
        }
 
        pipe_state->account_name = talloc_strdup(pipe_state->mem_ctx, r->in.account_name);
        
        if (pipe_state->computer_name) {
                /* We don't want a memory leak on this long-lived talloc context */
-               talloc_free(pipe_state->mem_ctx, pipe_state->account_name);
+               talloc_free(pipe_state->account_name);
        }
 
        pipe_state->computer_name = talloc_strdup(pipe_state->mem_ctx, r->in.computer_name);
index 4028a853d709b22a8c9ef8f179c87c1b71ebb6dd..d670a2f8dc1cef03e92a29b9ff4bb3b80dedb5cf 100644 (file)
@@ -572,7 +572,7 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
        a_state->sam_ctx = d_state->sam_ctx;
        a_state->access_mask = r->in.access_mask;
        a_state->domain_state = d_state;
-       a_state->account_dn = talloc_steal(mem_ctx, mem_ctx2, msg.dn);
+       a_state->account_dn = talloc_steal(mem_ctx2, msg.dn);
        a_state->account_sid = talloc_strdup(mem_ctx2, sidstr);
        a_state->account_name = talloc_strdup(mem_ctx2, groupname);
        if (!a_state->account_name || !a_state->account_sid) {
@@ -756,7 +756,7 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
        a_state->sam_ctx = d_state->sam_ctx;
        a_state->access_mask = r->in.access_mask;
        a_state->domain_state = d_state;
-       a_state->account_dn = talloc_steal(mem_ctx, mem_ctx2, msg.dn);
+       a_state->account_dn = talloc_steal(mem_ctx2, msg.dn);
        a_state->account_sid = talloc_strdup(mem_ctx2, sidstr);
        a_state->account_name = talloc_strdup(mem_ctx2, account_name);
        if (!a_state->account_name || !a_state->account_sid) {
@@ -1074,7 +1074,7 @@ static NTSTATUS samr_OpenGroup(struct dcesrv_call_state *dce_call, TALLOC_CTX *m
        a_state->sam_ctx = d_state->sam_ctx;
        a_state->access_mask = r->in.access_mask;
        a_state->domain_state = d_state;
-       a_state->account_dn = talloc_steal(mem_ctx, mem_ctx2, msgs[0]->dn);
+       a_state->account_dn = talloc_steal(mem_ctx2, msgs[0]->dn);
        a_state->account_sid = talloc_strdup(mem_ctx2, sidstr);
        a_state->account_name = talloc_strdup(mem_ctx2, groupname);
        if (!a_state->account_name || !a_state->account_sid) {
@@ -1453,7 +1453,7 @@ static NTSTATUS samr_OpenUser(struct dcesrv_call_state *dce_call, TALLOC_CTX *me
        a_state->sam_ctx = d_state->sam_ctx;
        a_state->access_mask = r->in.access_mask;
        a_state->domain_state = d_state;
-       a_state->account_dn = talloc_steal(mem_ctx, mem_ctx2, msgs[0]->dn);
+       a_state->account_dn = talloc_steal(mem_ctx2, msgs[0]->dn);
        a_state->account_sid = talloc_strdup(mem_ctx2, sidstr);
        a_state->account_name = talloc_strdup(mem_ctx2, account_name);
        if (!a_state->account_name || !a_state->account_sid) {
index e9aeb168bc4bfd0260447ad5a650c762f4d36393..e3f54bde654552294445f247b849b5ceb1bd698c 100644 (file)
@@ -89,7 +89,7 @@ static void req_setup_chain_reply(struct smbsrv_request *req, uint_t wct, uint_t
        /* over allocate by a small amount */
        req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; 
 
-       req->out.buffer = talloc_realloc(req->mem_ctx, req->out.buffer, req->out.allocated);
+       req->out.buffer = talloc_realloc(req->out.buffer, req->out.allocated);
        if (!req->out.buffer) {
                smbsrv_terminate_connection(req->smb_conn, "allocation failed");
        }
@@ -203,7 +203,7 @@ static void req_grow_allocation(struct smbsrv_request *req, uint_t new_size)
 
        /* we need to realloc */
        req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION;
-       buf2 = talloc_realloc(req->mem_ctx, req->out.buffer, req->out.allocated);
+       buf2 = talloc_realloc(req->out.buffer, req->out.allocated);
        if (buf2 == NULL) {
                smb_panic("out of memory in req_grow_allocation");
        }
index f080cd2abce392bdbbae80b956f1c7c7b8dfe9c0..5f73dc7497bfd361ba78f129f9a0ce8a7974fbee 100644 (file)
@@ -39,7 +39,7 @@ static void trans2_grow_data_allocation(struct smbsrv_request *req,
        if (new_size <= trans->out.data.length) {
                return;
        }
-       trans->out.data.data = talloc_realloc(req->mem_ctx, trans->out.data.data, new_size);
+       trans->out.data.data = talloc_realloc(trans->out.data.data, new_size);
 }
 
 
index 0a5ef6d34e275d96dbdf91a076a5a60f759fbe9d..7dc9e7fcbcbea8831097aa985426b201f46f0710 100644 (file)
@@ -79,7 +79,7 @@ static void rap_cli_push_paramdesc(struct rap_call *call, char desc)
        if (call->paramdesc != NULL)
                len = strlen(call->paramdesc);
 
-       call->paramdesc = talloc_realloc(call->mem_ctx, call->paramdesc,
+       call->paramdesc = talloc_realloc(call->paramdesc,
                                         len+2);
        call->paramdesc[len] = desc;
        call->paramdesc[len+1] = '\0';
index 8cdc18fe2f0e397b969561df28aa772f814d9a02..2cb39b3231b072095f5dc4460825493edf5f2cae 100644 (file)
@@ -150,7 +150,7 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_fileinfo finfo;
        const char *fname = BASEDIR "\\torture_open.txt";
        NTSTATUS status;
-       int fnum, fnum2;
+       int fnum = -1, fnum2;
        BOOL ret = True;
 
        printf("Checking RAW_OPEN_OPEN\n");
@@ -261,7 +261,7 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_fileinfo finfo;
        const char *fname = BASEDIR "\\torture_openx.txt";
        NTSTATUS status;
-       int fnum, fnum2;
+       int fnum = -1, fnum2;
        BOOL ret = True;
        int i;
        struct {
@@ -579,7 +579,7 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *fname = BASEDIR "\\torture_ntcreatex.txt";
        const char *dname = BASEDIR "\\torture_ntcreatex.dir";
        NTSTATUS status;
-       int fnum;
+       int fnum = -1;
        BOOL ret = True;
        int i;
        struct {
@@ -822,7 +822,7 @@ static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_open io;
        const char *fname = BASEDIR "\\torture_mknew.txt";
        NTSTATUS status;
-       int fnum;
+       int fnum = -1;
        BOOL ret = True;
        time_t basetime = (time(NULL) + 3600*24*3) & ~1;
        union smb_fileinfo finfo;
@@ -876,7 +876,7 @@ static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_open io;
        const char *fname = BASEDIR "\\torture_create.txt";
        NTSTATUS status;
-       int fnum;
+       int fnum = -1;
        BOOL ret = True;
        time_t basetime = (time(NULL) + 3600*24*3) & ~1;
        union smb_fileinfo finfo;
@@ -930,7 +930,7 @@ static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 {
        union smb_open io;
        NTSTATUS status;
-       int fnum;
+       int fnum = -1;
        BOOL ret = True;
        time_t basetime = (time(NULL) + 3600*24*3) & ~1;
        union smb_fileinfo finfo;
index f1d51a8c6932829386231acb725ee6327edbca2e..19dfcc51d4e3c4f799b8509588fcbccac0b8c609 100644 (file)
@@ -377,8 +377,7 @@ static BOOL multiple_search_callback(void *private, union smb_search_data *file)
 
 
        data->count++;
-       data->list = talloc_realloc(data->mem_ctx, 
-                                   data->list, 
+       data->list = talloc_realloc(data->list, 
                                    data->count * (sizeof(data->list[0])));
 
        data->list[data->count-1] = *file;
index 86b91eacc27903015c5ddd4fc3e6c47a40d57a4b..59f0fc4a042f8895e1479d8bab11d82de3720311 100644 (file)
@@ -488,8 +488,9 @@ static BOOL test_Open(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, void *fn)
        BOOL ret = True;
        winreg_open_fn *open_fn = (winreg_open_fn *)fn;
 
-       if (!open_fn(p, mem_ctx, &handle))
+       if (!open_fn(p, mem_ctx, &handle)) {
                return False;
+       }
 
        if (!test_CreateKey(p, mem_ctx, &handle, "spottyfoot", NULL)) {
                printf("CreateKey failed\n");