]> git.meshlink.io Git - meshlink/commitdiff
Zero the struct meshlink_handle in meshlink_close().
authorGuus Sliepen <guus@sliepen.org>
Tue, 29 Jul 2014 14:59:08 +0000 (16:59 +0200)
committerGuus Sliepen <guus@sliepen.org>
Tue, 29 Jul 2014 14:59:08 +0000 (16:59 +0200)
This prevents potentially bad behaviour when the application calls
meshlink_close() twice on the same pointer.

src/meshlink.c

index b3e87faaca293175b384b0a6b189cdaa4c26f97b..3651988fa5c9c66c337c2df5482a1a1df7350ae4 100644 (file)
@@ -853,11 +853,19 @@ void meshlink_close(meshlink_handle_t *mesh) {
        exit_configuration(&mesh->config);
        event_loop_exit(&mesh->loop);
 
-       free(mesh);
-
 #ifdef HAVE_MINGW
-       WSACleanup();
+       if(mesh->confbase)
+               WSACleanup();
 #endif
+
+       ecdsa_free(mesh->invitation_key);
+
+       free(mesh->name);
+       free(mesh->confbase);
+
+       free(mesh);
+
+       memset(mesh, 0, sizeof *mesh);
 }
 
 void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb) {