From ee314d6930881602962bfaeb81778b17314e1cf5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Aug 2008 18:34:54 +1000 Subject: fixed fetch of empty records (This used to be commit 037516f1362c8d64da1d47a0cdaf83198d3eaeaf) --- source3/lib/dbwrap_ctdb.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'source3') diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c index 0de61ceb6a..a6bda8e403 100644 --- a/source3/lib/dbwrap_ctdb.c +++ b/source3/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); -- cgit