]> git.meshlink.io Git - meshlink/commitdiff
Fix several memory leaks found by AddressSanitizer.
authorGuus Sliepen <guus@meshlink.io>
Fri, 4 Oct 2019 14:08:51 +0000 (16:08 +0200)
committerGuus Sliepen <guus@meshlink.io>
Fri, 4 Oct 2019 14:08:51 +0000 (16:08 +0200)
src/meshlink.c
test/ephemeral.c
test/trio.c
test/trio2.c

index f0a1b759fe989397c288149600f4fbb2e8316938..8ed946268b44aa58e3c79345ecd2e4547e8e273a 100644 (file)
@@ -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;
index 10a6e2beb7b296a9277e8ae3c7b2a36bc25651b3..6921b53904a68a3dd556937cd1a62043ec2ce86f 100644 (file)
@@ -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
 
index 79013a6f5e3ed016a144fad68bb2c52b249ecb5e..1dc33aa4480756f229c5fb275896e22c2ec4d9ff 100644 (file)
@@ -85,6 +85,7 @@ int main() {
        // start the nodes
 
        for(int i = 0; i < 3; i++) {
+               free(data[i]);
                assert(meshlink_start(mesh[i]));
        }
 
index d9b3a0f94454cf9ec58eeba0194d275ed7e42830..299a5582949b18ba28818e336d46bf19982764ae 100644 (file)
@@ -87,6 +87,7 @@ int main() {
        // start the nodes
 
        for(int i = 0; i < 3; i++) {
+               free(data[i]);
                assert(meshlink_start(mesh[i]));
        }