From: Andrew Tridgell Date: Thu, 7 Aug 2008 08:34:54 +0000 (+1000) Subject: fixed fetch of empty records X-Git-Tag: samba-3.3.0pre1~151 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=037516f1362c8d64da1d47a0cdaf83198d3eaeaf;p=thirdparty%2Fsamba.git fixed fetch of empty records --- diff --git a/source/lib/dbwrap_ctdb.c b/source/lib/dbwrap_ctdb.c index 0de61ceb6a8..a6bda8e4033 100644 --- a/source/lib/dbwrap_ctdb.c +++ b/source/lib/dbwrap_ctdb.c @@ -321,12 +321,16 @@ static int db_ctdb_transaction_fetch(struct db_ctdb_ctx *db, if (data->dptr != NULL) { uint8_t *oldptr = (uint8_t *)data->dptr; data->dsize -= sizeof(struct ctdb_ltdb_header); - data->dptr = (uint8 *) - talloc_memdup( - mem_ctx, data->dptr+sizeof(struct ctdb_ltdb_header), - data->dsize); + if (data->dsize == 0) { + data->dptr = NULL; + } else { + data->dptr = (uint8 *) + talloc_memdup( + mem_ctx, data->dptr+sizeof(struct ctdb_ltdb_header), + data->dsize); + } SAFE_FREE(oldptr); - if (data->dptr == NULL) { + if (data->dptr == NULL && data->dsize != 0) { return -1; } } @@ -439,7 +443,8 @@ static int db_ctdb_transaction_store(struct db_ctdb_transaction_handle *h, } } - rec.dptr = talloc_size(tmp_ctx, data.dsize + sizeof(struct ctdb_ltdb_header)); + rec.dsize = data.dsize + sizeof(struct ctdb_ltdb_header); + rec.dptr = talloc_size(tmp_ctx, rec.dsize); if (rec.dptr == NULL) { DEBUG(0,(__location__ " Failed to alloc record\n")); talloc_free(tmp_ctx);