diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-08-25 03:23:39 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:58:20 -0500 |
commit | 716e6c1efb55f6fdc01f63cf703b46464da609b2 (patch) | |
tree | 6de553c41e7e5f5e68d53c8dd1fdbaf8100f7195 /source4 | |
parent | 98875066fbb828803698f34ed33c52c0fa374732 (diff) | |
download | samba-716e6c1efb55f6fdc01f63cf703b46464da609b2.tar.gz samba-716e6c1efb55f6fdc01f63cf703b46464da609b2.tar.bz2 samba-716e6c1efb55f6fdc01f63cf703b46464da609b2.zip |
r2043: data_blob() now returns a talloc'd pointer. If everyone has been
following the data_blob() API properly then this will cause no
problems. I'm expecting chaos.
this is part of the general move towards using talloc for everything
in samba4
(This used to be commit 3f6b3c21e4d538aeb30b7906a75995b8f4c11223)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/data_blob.c | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/source4/lib/data_blob.c b/source4/lib/data_blob.c index 92950298aa..e10ebfe606 100644 --- a/source4/lib/data_blob.c +++ b/source4/lib/data_blob.c @@ -35,9 +35,13 @@ DATA_BLOB data_blob(const void *p, size_t length) } if (p) { - ret.data = smb_xmemdup(p, length); + ret.data = talloc_memdup(NULL, p, length); } else { - ret.data = smb_xmalloc(length); + ret.data = talloc(NULL, length); + } + if (ret.data == NULL) { + ret.length = 0; + return ret; } ret.length = length; return ret; @@ -48,29 +52,11 @@ DATA_BLOB data_blob(const void *p, size_t length) *******************************************************************/ DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length) { - DATA_BLOB ret; - - if (length == 0) { - ZERO_STRUCT(ret); - return ret; - } - - if (p == NULL) { - /* note that we do NOT zero memory in this case */ - ret.data = talloc(mem_ctx, length); - if (ret.data == NULL) { - smb_panic("data_blob_talloc: talloc_memdup failed.\n"); - } - ret.length = length; - return ret; - } + DATA_BLOB ret = data_blob(p, length); - ret.data = talloc_memdup(mem_ctx, p, length); - if (ret.data == NULL) { - smb_panic("data_blob_talloc: talloc_memdup failed.\n"); + if (ret.data) { + ret.data = talloc_steal(mem_ctx, ret.data); } - - ret.length = length; return ret; } @@ -86,29 +72,13 @@ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) return blob; } -/** - * Steal a talloc'ed DATA_BLOB from one context to another - */ - -DATA_BLOB data_blob_talloc_steal(TALLOC_CTX *old_ctx, TALLOC_CTX *new_ctx, - DATA_BLOB *old) -{ - DATA_BLOB new; - new = *old; - new.data = talloc_steal(new_ctx, old->data); - if (new.data == NULL) { - smb_panic("data_blob_talloc_steal: talloc_steal failed.\n"); - } - return new; -} - /******************************************************************* free a data blob *******************************************************************/ void data_blob_free(DATA_BLOB *d) { if (d) { - free(d->data); + talloc_free(d->data); d->data = NULL; d->length = 0; } |