From ebb94d96cb93d1646ed8bbdf8030ba4203fefcbb Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 7 Sep 2017 11:05:06 -0500 Subject: [PATCH] Sorting a memory leak in datastore/journalstore --- db/datastore.c | 5 +++-- include/libp2p/db/datastore.h | 3 +-- net/multistream.c | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/db/datastore.c b/db/datastore.c index 109172a..873ca04 100644 --- a/db/datastore.c +++ b/db/datastore.c @@ -41,7 +41,7 @@ int libp2p_datastore_new(struct Datastore** datastore) { if (*datastore == NULL) return 0; (*datastore)->path = NULL; - (*datastore)->handle = NULL; + (*datastore)->datastore_handle = NULL; (*datastore)->type = NULL; (*datastore)->storage_max = NULL; (*datastore)->gc_period = NULL; @@ -67,7 +67,7 @@ int libp2p_datastore_free(struct Datastore* datastore) { free(datastore->gc_period); if (datastore->params != NULL) free(datastore->params); - if (datastore->handle != NULL) + if (datastore->datastore_handle != NULL) datastore->datastore_close(datastore); free(datastore); } @@ -99,6 +99,7 @@ int libp2p_datastore_record_free(struct DatastoreRecord* rec) { } rec->value_size = 0; rec->timestamp = 0; + free(rec); } return 1; } diff --git a/include/libp2p/db/datastore.h b/include/libp2p/db/datastore.h index 450d658..d9d13a8 100644 --- a/include/libp2p/db/datastore.h +++ b/include/libp2p/db/datastore.h @@ -36,8 +36,7 @@ struct Datastore { int (*datastore_cursor_close)(struct Datastore* datastore); int (*datastore_cursor_get)(unsigned char** key, int* key_length, unsigned char** value, int* value_length, enum DatastoreCursorOp op, struct Datastore* datastore); // generic connection and status variables for the datastore - void* handle; // a handle to the database - void* cursor; // a current cursor + void* datastore_handle; // a handle to the database }; /*** diff --git a/net/multistream.c b/net/multistream.c index 79d6c5a..a48b4e9 100644 --- a/net/multistream.c +++ b/net/multistream.c @@ -84,6 +84,10 @@ int libp2p_net_multistream_handle_message(const uint8_t *incoming, size_t incomi } int libp2p_net_multistream_shutdown(void* protocol_context) { + struct MultistreamContext* context = (struct MultistreamContext*) protocol_context; + if (context != NULL) { + free(context); + } return 1; }