summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctdb/common/ctdb_ltdb.c4
-rw-r--r--ctdb/include/ctdb_private.h5
2 files changed, 8 insertions, 1 deletions
diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c
index 881cf48630..8958140002 100644
--- a/ctdb/common/ctdb_ltdb.c
+++ b/ctdb/common/ctdb_ltdb.c
@@ -79,6 +79,7 @@ int ctdb_ltdb_fetch(struct ctdb_context *ctdb,
if (rec.dsize < sizeof(*header)) {
/* return an initial header */
ltdb_initial_header(ctdb, key, header);
+ SAFE_FREE(rec.dptr);
data->dptr = NULL;
data->dsize = 0;
return 0;
@@ -89,6 +90,7 @@ int ctdb_ltdb_fetch(struct ctdb_context *ctdb,
data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header);
data->dptr = talloc_memdup(ctdb, sizeof(struct ctdb_ltdb_header)+rec.dptr,
data->dsize);
+ SAFE_FREE(rec.dptr);
CTDB_NO_MEMORY(ctdb, data->dptr);
return 0;
@@ -106,7 +108,7 @@ int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key,
TDB_DATA rec;
int ret;
- rec.dsize = sizeof(struct ctdb_ltdb_header) + data.dsize;
+ rec.dsize = sizeof(*header) + data.dsize;
rec.dptr = talloc_size(ctdb, rec.dsize);
CTDB_NO_MEMORY(ctdb, rec.dptr);
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index f21139eab2..d4e89c83c1 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -186,6 +186,11 @@ struct ctdb_reply_dmaster {
uint8_t data[0];
};
+/* free memory if the pointer is valid and zero the pointer */
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
+#endif
+
/* internal prototypes */
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);