r2039: got rid of the free() ptr in DATA_BLOB
authorAndrew Tridgell <tridge@samba.org>
Wed, 25 Aug 2004 02:07:20 +0000 (02:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:58:19 +0000 (12:58 -0500)
I plan on replacing the concept by adding a generic destructor in all talloc ptrs, so you can do:

  talloc_set_destructor(ptr, my_destructor);

to setup a function that will be called on free.
(This used to be commit 957b260621c091830c01e9e8c370c199350342ec)

source4/include/rewrite.h
source4/lib/data_blob.c

index 626a4673311ef8e65770572cab0bb136eec0719f..0bac4ab19e237e6fd7221e58269a4bf395730e84 100644 (file)
@@ -78,7 +78,6 @@ typedef smb_ucs2_t wfstring[FSTRING_LEN];
 typedef struct data_blob {
        uint8_t *data;
        size_t length;
-       void (*free)(struct data_blob *data_blob);
 } DATA_BLOB;
 
 #include "enums.h"
index bc5cf9abc869f83232f25646e22077e10acde5a2..92950298aa9fe549c470a3d01c46e9ba4f7a3d43 100644 (file)
 
 #include "includes.h"
 
-/*******************************************************************
- free() a data blob
-*******************************************************************/
-static void free_data_blob(DATA_BLOB *d)
-{
-       if ((d) && (d->free)) {
-               SAFE_FREE(d->data);
-       }
-}
-
 /*******************************************************************
  construct a data blob, must be freed with data_blob_free()
  you can pass NULL for p and get a blank data blob
@@ -39,7 +29,7 @@ DATA_BLOB data_blob(const void *p, size_t length)
 {
        DATA_BLOB ret;
 
-       if (!length) {
+       if (length == 0) {
                ZERO_STRUCT(ret);
                return ret;
        }
@@ -50,7 +40,6 @@ DATA_BLOB data_blob(const void *p, size_t length)
                ret.data = smb_xmalloc(length);
        }
        ret.length = length;
-       ret.free = free_data_blob;
        return ret;
 }
 
@@ -73,7 +62,6 @@ DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length)
                        smb_panic("data_blob_talloc: talloc_memdup failed.\n");
                }
                ret.length = length;
-               ret.free = NULL;
                return ret;
        }
 
@@ -83,7 +71,6 @@ DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length)
        }
 
        ret.length = length;
-       ret.free = NULL;
        return ret;
 }
 
@@ -121,9 +108,7 @@ free a data blob
 void data_blob_free(DATA_BLOB *d)
 {
        if (d) {
-               if (d->free) {
-                       (d->free)(d);
-               }
+               free(d->data);
                d->data = NULL;
                d->length = 0;
        }