mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
Fix memory handling
(This used to be ctdb commit a7ff834cec4c44eee7d1a84218e050a45b94d599)
This commit is contained in:
parent
ee547a0f9a
commit
1d8c33e2a1
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user