Sorting a memory leak in datastore/journalstore

yamux
John Jones 2017-09-07 11:05:06 -05:00
parent 9fd44b7878
commit ebb94d96cb
3 changed files with 8 additions and 4 deletions

View File

@ -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;
}

View File

@ -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
};
/***

View File

@ -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;
}