summaryrefslogtreecommitdiffstats
path: root/ctdb/lib/tdb
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-07-30 13:10:33 -0700
committerRusty Russell <rusty@rustcorp.com.au>2009-08-04 16:50:48 +0930
commit6e4577d08f32f1a145c3df9276d1d4dfeb16cd0e (patch)
tree9b9fa7609582ae5dbaf9bdc53de6327e7ccd6b4e /ctdb/lib/tdb
parent1664d75ad3a5b710eaba9acb00d5996cd26cf2dc (diff)
downloadsamba-6e4577d08f32f1a145c3df9276d1d4dfeb16cd0e.tar.gz
samba-6e4577d08f32f1a145c3df9276d1d4dfeb16cd0e.tar.xz
samba-6e4577d08f32f1a145c3df9276d1d4dfeb16cd0e.zip
realloc() has that horrible overloaded free semantic when size is 0: current code does a free of the old record in this case, then fail.
(This used to be ctdb commit 8b6a5bba93843cd83b7b386b82949ad88f29884a)
Diffstat (limited to 'ctdb/lib/tdb')
-rw-r--r--ctdb/lib/tdb/common/tdb.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ctdb/lib/tdb/common/tdb.c b/ctdb/lib/tdb/common/tdb.c
index a0125f17dab..721700344c6 100644
--- a/ctdb/lib/tdb/common/tdb.c
+++ b/ctdb/lib/tdb/common/tdb.c
@@ -584,8 +584,13 @@ 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 {
- unsigned char *new_dptr = (unsigned char *)realloc(dbuf.dptr,
- dbuf.dsize + new_dbuf.dsize);
+ unsigned int new_len = dbuf.dsize + new_dbuf.dsize;
+ unsigned char *new_dptr;
+
+ /* realloc '0' is special: don't do that. */
+ if (new_len == 0)
+ new_len = 1;
+ new_dptr = (unsigned char *)realloc(dbuf.dptr, new_len);
if (new_dptr == NULL) {
free(dbuf.dptr);
}