r23590: Fix realloc leak on failure case from Jim Meyering <jim@meyering.net>.
authorJeremy Allison <jra@samba.org>
Fri, 22 Jun 2007 17:36:10 +0000 (17:36 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:53:28 +0000 (14:53 -0500)
Jeremy.

source/lib/tdb/common/tdb.c

index 70d050e7e6d633ece2add684c894bdbb9d69ac1d..28129a8c8ed81381e75640aa3aa8eaf91a8203b6 100644 (file)
@@ -579,8 +579,12 @@ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
        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) {