From 6db507deb75ac73c0bae86e830372b532aec834e Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 4 Oct 2019 16:08:51 +0200 Subject: [PATCH] Fix several memory leaks found by AddressSanitizer. --- src/meshlink.c | 2 ++ test/ephemeral.c | 13 +++++++++++-- test/trio.c | 1 + test/trio2.c | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index f0a1b759..8ed94626 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -2743,6 +2743,8 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { pthread_mutex_unlock(&(mesh->mesh_mutex)); + free(buf); + if(!packmsg_done(&in)) { logger(mesh, MESHLINK_ERROR, "Invalid data\n"); meshlink_errno = MESHLINK_EPEER; diff --git a/test/ephemeral.c b/test/ephemeral.c index 10a6e2be..6921b539 100644 --- a/test/ephemeral.c +++ b/test/ephemeral.c @@ -38,8 +38,17 @@ int main() { // Exchange data - assert(meshlink_import(mesh1, meshlink_export(mesh2))); - assert(meshlink_import(mesh2, meshlink_export(mesh1))); + char *export1 = meshlink_export(mesh1); + char *export2 = meshlink_export(mesh2); + + assert(export1); + assert(export2); + + assert(meshlink_import(mesh1, export2)); + assert(meshlink_import(mesh2, export1)); + + free(export1); + free(export2); // Check that they know each other diff --git a/test/trio.c b/test/trio.c index 79013a6f..1dc33aa4 100644 --- a/test/trio.c +++ b/test/trio.c @@ -85,6 +85,7 @@ int main() { // start the nodes for(int i = 0; i < 3; i++) { + free(data[i]); assert(meshlink_start(mesh[i])); } diff --git a/test/trio2.c b/test/trio2.c index d9b3a0f9..299a5582 100644 --- a/test/trio2.c +++ b/test/trio2.c @@ -87,6 +87,7 @@ int main() { // start the nodes for(int i = 0; i < 3; i++) { + free(data[i]); assert(meshlink_start(mesh[i])); } -- 2.39.5