From: Guus Sliepen Date: Tue, 4 May 2021 19:52:55 +0000 (+0200) Subject: Fix several memory leaks. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=31aaf60e9b10caedd9aaf2a22ce1af2d60c5bb9d;p=meshlink Fix several memory leaks. Found by the AddressSanitizer. --- diff --git a/src/meshlink.c b/src/meshlink.c index 4280c4f1..5d5733e7 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -3399,6 +3399,7 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { if(!buflen) { logger(mesh, MESHLINK_DEBUG, "Invalid data\n"); + free(buf); meshlink_errno = MESHLINK_EPEER; return false; } @@ -3408,6 +3409,7 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { if(!count) { logger(mesh, MESHLINK_DEBUG, "Invalid data\n"); + free(buf); meshlink_errno = MESHLINK_EPEER; return false; } @@ -3464,6 +3466,7 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { if(!node_write_config(mesh, n, true)) { free_node(n); + free(buf); return false; } diff --git a/test/channels-aio-fd.c b/test/channels-aio-fd.c index 78d9078b..3cac823c 100644 --- a/test/channels-aio-fd.c +++ b/test/channels-aio-fd.c @@ -175,4 +175,5 @@ int main(void) { // Clean up. close_meshlink_pair(mesh_a, mesh_b); + free(outdata); } diff --git a/test/channels-aio.c b/test/channels-aio.c index d424b843..19472bad 100644 --- a/test/channels-aio.c +++ b/test/channels-aio.c @@ -189,9 +189,12 @@ int main(void) { // The non-AIO transfer should have completed before everything else assert(!timespec_lt(&out_infos[i].aio_infos[0].ts, &b_received_ts)); assert(!timespec_lt(&in_infos[i].aio_infos[0].ts, &b_received_ts)); + + free(in_infos[i].data); } // Clean up. close_meshlink_pair(mesh_a, mesh_b); + free(outdata); } diff --git a/test/get-all-nodes.c b/test/get-all-nodes.c index 152184c6..33adb9a3 100644 --- a/test/get-all-nodes.c +++ b/test/get-all-nodes.c @@ -77,6 +77,8 @@ int main(void) { assert(meshlink_import(mesh[j], data)); } + + free(data); } // We should know about all nodes now, and their device class. diff --git a/test/storage-policy.c b/test/storage-policy.c index ed78334b..a9aa5f49 100644 --- a/test/storage-policy.c +++ b/test/storage-policy.c @@ -207,4 +207,5 @@ int main(void) { // Done. close_meshlink_pair(mesh1, mesh2); + free(invitation); }