]> git.meshlink.io Git - meshlink/commitdiff
Fix several memory leaks.
authorGuus Sliepen <guus@meshlink.io>
Tue, 4 May 2021 19:52:55 +0000 (21:52 +0200)
committerGuus Sliepen <guus@meshlink.io>
Tue, 4 May 2021 19:54:19 +0000 (21:54 +0200)
Found by the AddressSanitizer.

src/meshlink.c
test/channels-aio-fd.c
test/channels-aio.c
test/get-all-nodes.c
test/storage-policy.c

index 4280c4f13797c27919f1790ac5be59ce442a12d8..5d5733e7bf432e26d7d1923c510c39edd6a41a9b 100644 (file)
@@ -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;
                }
 
index 78d9078b1b59ed2aabbc322ed4a90ad95d1f8810..3cac823c5c0943ceb37e11bd816264ae81373e70 100644 (file)
@@ -175,4 +175,5 @@ int main(void) {
        // Clean up.
 
        close_meshlink_pair(mesh_a, mesh_b);
+       free(outdata);
 }
index d424b843703096c54ae72953571fd7ba8c49ff9a..19472bad61b0751f9d826aa74ec41cc18fbf0b24 100644 (file)
@@ -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);
 }
index 152184c67a7a4092a03bfdf57481c7cb575f80f4..33adb9a39efd1943daeaa00ec93a156036b7fb29 100644 (file)
@@ -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.
index ed78334b67b2545a3bbbc12f4735dc04386ba953..a9aa5f49b5eeda958fb1de6315c7dc6034de7340 100644 (file)
@@ -207,4 +207,5 @@ int main(void) {
        // Done.
 
        close_meshlink_pair(mesh1, mesh2);
+       free(invitation);
 }