svn commit: samba r23590 - in branches: SAMBA_3_0/source/lib/tdb/common SAMBA_3_0_25/source/tdb/common SAMBA_3_0_26/source/lib/tdb/common SAMBA_4_0/source/lib/tdb/common

jra at samba.org jra at samba.org
Fri Jun 22 17:36:13 GMT 2007


Author: jra
Date: 2007-06-22 17:36:10 +0000 (Fri, 22 Jun 2007)
New Revision: 23590

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23590

Log:
Fix realloc leak on failure case from Jim Meyering  <jim at meyering.net>.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/lib/tdb/common/tdb.c
   branches/SAMBA_3_0_25/source/tdb/common/tdb.c
   branches/SAMBA_3_0_26/source/lib/tdb/common/tdb.c
   branches/SAMBA_4_0/source/lib/tdb/common/tdb.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/tdb/common/tdb.c
===================================================================
--- branches/SAMBA_3_0/source/lib/tdb/common/tdb.c	2007-06-22 17:19:08 UTC (rev 23589)
+++ branches/SAMBA_3_0/source/lib/tdb/common/tdb.c	2007-06-22 17:36:10 UTC (rev 23590)
@@ -566,8 +566,12 @@
 	if (dbuf.dptr == NULL) {
 		dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);
 	} else {
-		dbuf.dptr = (unsigned char *)realloc(dbuf.dptr,
+		unsigned char *new_dptr = (unsigned char *)realloc(dbuf.dptr,
 						     dbuf.dsize + new_dbuf.dsize);
+		if (new_dptr == NULL) {
+			free(dbuf.dptr);
+		}
+		dbuf.dptr = new_dptr;
 	}
 
 	if (dbuf.dptr == NULL) {

Modified: branches/SAMBA_3_0_25/source/tdb/common/tdb.c
===================================================================
--- branches/SAMBA_3_0_25/source/tdb/common/tdb.c	2007-06-22 17:19:08 UTC (rev 23589)
+++ branches/SAMBA_3_0_25/source/tdb/common/tdb.c	2007-06-22 17:36:10 UTC (rev 23590)
@@ -566,8 +566,12 @@
 	if (dbuf.dptr == NULL) {
 		dbuf.dptr = (char *)malloc(new_dbuf.dsize);
 	} else {
-		dbuf.dptr = (char *)realloc(dbuf.dptr,
+		char *new_dptr = (char *)realloc(dbuf.dptr,
 					    dbuf.dsize + new_dbuf.dsize);
+		if (new_dptr == NULL) {
+			free(dbuf.dptr);
+		}
+		dbuf.dptr = new_dptr;
 	}
 
 	if (dbuf.dptr == NULL) {

Modified: branches/SAMBA_3_0_26/source/lib/tdb/common/tdb.c
===================================================================
--- branches/SAMBA_3_0_26/source/lib/tdb/common/tdb.c	2007-06-22 17:19:08 UTC (rev 23589)
+++ branches/SAMBA_3_0_26/source/lib/tdb/common/tdb.c	2007-06-22 17:36:10 UTC (rev 23590)
@@ -566,8 +566,12 @@
 	if (dbuf.dptr == NULL) {
 		dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);
 	} else {
-		dbuf.dptr = (unsigned char *)realloc(dbuf.dptr,
+		unsigned char *new_dptr = (unsigned char *)realloc(dbuf.dptr,
 						     dbuf.dsize + new_dbuf.dsize);
+		if (new_dptr == NULL) {
+			free(dbuf.dptr);
+		}
+		dbuf.dptr = new_dptr;
 	}
 
 	if (dbuf.dptr == NULL) {

Modified: branches/SAMBA_4_0/source/lib/tdb/common/tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/tdb.c	2007-06-22 17:19:08 UTC (rev 23589)
+++ branches/SAMBA_4_0/source/lib/tdb/common/tdb.c	2007-06-22 17:36:10 UTC (rev 23590)
@@ -579,8 +579,12 @@
 	if (dbuf.dptr == NULL) {
 		dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);
 	} else {
-		dbuf.dptr = (unsigned char *)realloc(dbuf.dptr,
+		unsigned char *new_dptr = (unsigned char *)realloc(dbuf.dptr,
 						     dbuf.dsize + new_dbuf.dsize);
+		if (new_dptr == NULL) {
+			free(dbuf.dptr);
+		}
+		dbuf.dptr = new_dptr;
 	}
 
 	if (dbuf.dptr == NULL) {



More information about the samba-cvs mailing list