1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

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)
This commit is contained in:
Andrew Tridgell 2004-08-25 03:23:39 +00:00 committed by Gerald (Jerry) Carter
parent 98875066fb
commit 716e6c1efb

View File

@ -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;
DATA_BLOB ret = data_blob(p, length);
if (length == 0) {
ZERO_STRUCT(ret);
return ret;
if (ret.data) {
ret.data = talloc_steal(mem_ctx, ret.data);
}
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;
}
ret.data = talloc_memdup(mem_ctx, p, length);
if (ret.data == NULL) {
smb_panic("data_blob_talloc: talloc_memdup failed.\n");
}
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;
}