svn commit: samba r2043 - branches/SAMBA_4_0/source/lib

tridge at samba.org tridge at samba.org
Wed Aug 25 03:23:39 GMT 2004


Author: tridge
Date: 2004-08-25 03:23:39 +0000 (Wed, 25 Aug 2004)
New Revision: 2043

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/&rev=2043&nolog=1

Log:
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

Modified:
   branches/SAMBA_4_0/source/lib/data_blob.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/data_blob.c
===================================================================
--- branches/SAMBA_4_0/source/lib/data_blob.c	2004-08-25 02:25:48 UTC (rev 2042)
+++ branches/SAMBA_4_0/source/lib/data_blob.c	2004-08-25 03:23:39 UTC (rev 2043)
@@ -35,10 +35,14 @@
 	}
 
 	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_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 @@
 	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;
 	}



More information about the samba-cvs mailing list