From: Andrew Tridgell Date: Sat, 7 Apr 2007 00:45:00 +0000 (+1000) Subject: fixed a bunch of memory leaks X-Git-Tag: tevent-0.9.20~348^2~2958 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=01c4a086e79ee0352dc133b8adb6e38f5ee35e56;p=thirdparty%2Fsamba.git fixed a bunch of memory leaks (This used to be ctdb commit 2ba2522f2def3032c89c7973915610a245842b07) --- diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index da07192c215..b98c0a3d841 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -246,9 +246,9 @@ static void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t len default: printf("Packet with unknown operation %d\n", hdr->operation); - talloc_free(hdr); break; } + talloc_free(hdr); } /* diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c index decdbe127fd..7b4094fe4aa 100644 --- a/ctdb/common/ctdb_call.c +++ b/ctdb/common/ctdb_call.c @@ -56,11 +56,13 @@ static int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *ca } if (fn == NULL) { ctdb_set_error(ctdb, "Unknown call id %u\n", call->call_id); + talloc_free(c); return -1; } if (fn->fn(c) != 0) { ctdb_set_error(ctdb, "ctdb_call %u failed\n", call->call_id); + talloc_free(c); return -1; } @@ -79,6 +81,7 @@ static int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *ca if (c->new_data) { if (ctdb_ltdb_store(ctdb_db, call->key, header, *c->new_data) != 0) { ctdb_set_error(ctdb, "ctdb_call tdb_store failed\n"); + talloc_free(c); return -1; } } @@ -123,6 +126,7 @@ static void ctdb_send_error(struct ctdb_context *ctdb, len = offsetof(struct ctdb_reply_error, msg); r = ctdb->methods->allocate_pkt(ctdb, len + msglen); CTDB_NO_MEMORY_FATAL(ctdb, r); + talloc_set_name_const(r, "send_error packet"); r->hdr.length = len + msglen; r->hdr.ctdb_magic = CTDB_MAGIC; @@ -154,6 +158,7 @@ static void ctdb_call_send_redirect(struct ctdb_context *ctdb, r = ctdb->methods->allocate_pkt(ctdb, sizeof(*r)); CTDB_NO_MEMORY_FATAL(ctdb, r); + talloc_set_name_const(r, "send_redirect packet"); r->hdr.length = sizeof(*r); r->hdr.ctdb_magic = CTDB_MAGIC; r->hdr.ctdb_version = CTDB_VERSION; @@ -187,6 +192,7 @@ static void ctdb_call_send_dmaster(struct ctdb_db_context *ctdb_db, len = offsetof(struct ctdb_req_dmaster, data) + key->dsize + data->dsize; r = ctdb->methods->allocate_pkt(ctdb, len); CTDB_NO_MEMORY_FATAL(ctdb, r); + talloc_set_name_const(r, "send_dmaster packet"); r->hdr.length = len; r->hdr.ctdb_magic = CTDB_MAGIC; r->hdr.ctdb_version = CTDB_VERSION; @@ -247,7 +253,7 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr } /* fetch the current record */ - ret = ctdb_ltdb_fetch(ctdb_db, key, &header, &data2); + ret = ctdb_ltdb_fetch(ctdb_db, key, &header, hdr, &data2); if (ret != 0) { ctdb_fatal(ctdb, "ctdb_req_dmaster failed to fetch record"); return; @@ -269,6 +275,7 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr len = offsetof(struct ctdb_reply_dmaster, data) + data.dsize; r = ctdb->methods->allocate_pkt(ctdb, len); CTDB_NO_MEMORY_FATAL(ctdb, r); + talloc_set_name_const(r, "reply_dmaster packet"); r->hdr.length = len; r->hdr.ctdb_magic = CTDB_MAGIC; r->hdr.ctdb_version = CTDB_VERSION; @@ -322,7 +329,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) fetches the record data (if any), thus avoiding a 2nd fetch of the data if the call will be answered locally */ - ret = ctdb_ltdb_fetch(ctdb_db, call.key, &header, &data); + ret = ctdb_ltdb_fetch(ctdb_db, call.key, &header, hdr, &data); if (ret != 0) { ctdb_send_error(ctdb, hdr, ret, "ltdb fetch failed in ctdb_request_call"); return; @@ -353,6 +360,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) len = offsetof(struct ctdb_reply_call, data) + call.reply_data.dsize; r = ctdb->methods->allocate_pkt(ctdb, len); CTDB_NO_MEMORY_FATAL(ctdb, r); + talloc_set_name_const(r, "reply_call packet"); r->hdr.length = len; r->hdr.ctdb_magic = CTDB_MAGIC; r->hdr.ctdb_version = CTDB_VERSION; @@ -571,7 +579,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c locally. To find out if we are the dmaster we need to look in our ltdb */ - ret = ctdb_ltdb_fetch(ctdb_db, call->key, &header, &data); + ret = ctdb_ltdb_fetch(ctdb_db, call->key, &header, ctdb, &data); if (ret != 0) return NULL; if (header.dmaster == ctdb->vnn && !(ctdb->flags & CTDB_FLAG_SELF_CONNECT)) { @@ -581,9 +589,13 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c state = talloc_zero(ctdb_db, struct ctdb_call_state); CTDB_NO_MEMORY_NULL(ctdb, state); + talloc_steal(state, data.dptr); + len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize; state->c = ctdb->methods->allocate_pkt(ctdb, len); CTDB_NO_MEMORY_NULL(ctdb, state->c); + talloc_set_name_const(state->c, "req_call packet"); + talloc_steal(state, state->c); state->c->hdr.length = len; state->c->hdr.ctdb_magic = CTDB_MAGIC; @@ -650,8 +662,7 @@ int ctdb_call_recv(struct ctdb_call_state *state, struct ctdb_call *call) /* ugly hack to manage forced migration */ if (rec != NULL) { - rec->data->dptr = talloc_memdup(rec, state->call.reply_data.dptr, - state->call.reply_data.dsize); + rec->data->dptr = talloc_steal(rec, state->call.reply_data.dptr); rec->data->dsize = state->call.reply_data.dsize; talloc_free(state); return 0; @@ -726,7 +737,7 @@ int ctdb_record_store(struct ctdb_record_handle *rec, TDB_DATA data) struct ctdb_ltdb_header header; /* should be avoided if possible hang header off rec ? */ - ret = ctdb_ltdb_fetch(rec->ctdb_db, rec->key, &header, NULL); + ret = ctdb_ltdb_fetch(rec->ctdb_db, rec->key, &header, NULL, NULL); if (ret) { ctdb_set_error(rec->ctdb_db->ctdb, "Fetch of locally held record failed"); return ret; diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c index ceedb6c5ced..84c3bd49dac 100644 --- a/ctdb/common/ctdb_ltdb.c +++ b/ctdb/common/ctdb_ltdb.c @@ -137,7 +137,8 @@ static void ltdb_initial_header(struct ctdb_db_context *ctdb_db, returned if the record is not present */ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, - TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data) + TDB_DATA key, struct ctdb_ltdb_header *header, + TALLOC_CTX *mem_ctx, TDB_DATA *data) { TDB_DATA rec; struct ctdb_context *ctdb = ctdb_db->ctdb; @@ -158,7 +159,8 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, if (data) { data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); - data->dptr = talloc_memdup(ctdb_db, sizeof(struct ctdb_ltdb_header)+rec.dptr, + data->dptr = talloc_memdup(mem_ctx, + sizeof(struct ctdb_ltdb_header)+rec.dptr, data->dsize); } diff --git a/ctdb/common/ctdb_message.c b/ctdb/common/ctdb_message.c index d866d7876fc..99e4a5aacb3 100644 --- a/ctdb/common/ctdb_message.c +++ b/ctdb/common/ctdb_message.c @@ -41,13 +41,11 @@ void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr if (ctdb->message_handler == NULL) { printf("no msg handler\n"); /* no registered message handler */ - talloc_free(hdr); return; } data.dptr = &c->data[0]; data.dsize = c->datalen; ctdb->message_handler(ctdb, c->srvid, data, ctdb->message_private); - talloc_free(hdr); } @@ -63,6 +61,7 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn, len = offsetof(struct ctdb_req_message, data) + data.dsize; r = ctdb->methods->allocate_pkt(ctdb, len); CTDB_NO_MEMORY(ctdb, r); + talloc_set_name_const(r, "req_message packet"); r->hdr.length = len; r->hdr.ctdb_magic = CTDB_MAGIC; diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 9c93466e19c..00b74b21779 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -240,7 +240,8 @@ void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key); int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, - TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data); + TDB_DATA key, struct ctdb_ltdb_header *header, + TALLOC_CTX *mem_ctx, TDB_DATA *data); int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA data); void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr); diff --git a/ctdb/tests/bench.sh b/ctdb/tests/bench.sh index a55f7b78d72..50e9e08f995 100755 --- a/ctdb/tests/bench.sh +++ b/ctdb/tests/bench.sh @@ -3,7 +3,7 @@ killall -q ctdb_bench echo "Trying 2 nodes" -bin/ctdb_bench --nlist nodes.txt --listen 127.0.0.2:9001 $* & -bin/ctdb_bench --nlist nodes.txt --listen 127.0.0.1:9001 $* +bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* & +bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.1:9001 $* killall -q ctdb_bench diff --git a/ctdb/tests/ctdb_fetch.c b/ctdb/tests/ctdb_fetch.c index c0491e9bb5a..c77a5cb7056 100644 --- a/ctdb/tests/ctdb_fetch.c +++ b/ctdb/tests/ctdb_fetch.c @@ -280,6 +280,8 @@ int main(int argc, const char *argv[]) printf("DATA:\n%s\n", (char *)call.reply_data.dptr); + talloc_report_full(ctdb, stdout); + /* shut it down */ talloc_free(ctdb); return 0; diff --git a/ctdb/tests/fetch.sh b/ctdb/tests/fetch.sh index fd23e67f274..42d5cc17170 100755 --- a/ctdb/tests/fetch.sh +++ b/ctdb/tests/fetch.sh @@ -3,7 +3,7 @@ killall -q ctdb_fetch echo "Trying 2 nodes" -bin/ctdb_fetch --nlist nodes.txt --listen 127.0.0.2:9001 $* & -bin/ctdb_fetch --nlist nodes.txt --listen 127.0.0.1:9001 $* +bin/ctdb_fetch --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* & +bin/ctdb_fetch --nlist tests/nodes.txt --listen 127.0.0.1:9001 $* killall -q ctdb_fetch diff --git a/ctdb/nodes.txt b/ctdb/tests/nodes.txt similarity index 100% rename from ctdb/nodes.txt rename to ctdb/tests/nodes.txt diff --git a/ctdb/tests/test.sh b/ctdb/tests/test.sh index 144e92a66c1..a72fdf1907f 100755 --- a/ctdb/tests/test.sh +++ b/ctdb/tests/test.sh @@ -3,8 +3,8 @@ killall -q ctdb_test echo "Trying 2 nodes" -bin/ctdb_test --nlist nodes.txt --listen 127.0.0.1:9001 & -bin/ctdb_test --nlist nodes.txt --listen 127.0.0.2:9001 & +bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.1:9001 & +bin/ctdb_test --nlist tests/nodes.txt --listen 127.0.0.2:9001 & sleep 3 killall ctdb_test