fixed fetch of empty records
authorAndrew Tridgell <tridge@samba.org>
Thu, 7 Aug 2008 08:34:54 +0000 (18:34 +1000)
committerMichael Adam <obnox@samba.org>
Wed, 13 Aug 2008 09:54:09 +0000 (11:54 +0200)
(This used to be commit 037516f1362c8d64da1d47a0cdaf83198d3eaeaf)

source3/lib/dbwrap_ctdb.c

index 0de61ceb6a8372be090f03a74c477ee743c67316..a6bda8e403331c7f8a30f1a6676fd8c908c5e6dc 100644 (file)
@@ -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);