]> git.meshlink.io Git - meshlink/commitdiff
bugfix handle case where count(edges) = 0
authorNiklas Hofmann <niklas.hofmann@everbase.net>
Thu, 14 Aug 2014 08:18:52 +0000 (10:18 +0200)
committerNiklas Hofmann <niklas.hofmann@everbase.net>
Thu, 14 Aug 2014 08:18:52 +0000 (10:18 +0200)
src/devtools.c

index 9c017307e6c947de293e2d968724d177296cf117..d287f3c99ae298ae4c265ea28bd861baa7e722b4 100644 (file)
@@ -54,7 +54,7 @@ bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE* stream)
        meshlink_node_t **nodes = meshlink_get_all_nodes(mesh, NULL, &node_count);
        meshlink_edge_t **edges = meshlink_get_all_edges_state(mesh, NULL, &edge_count);
 
-       if(!nodes || !edges)
+       if((!nodes && node_count != 0) || (!edges && edge_count != 0))
                { goto fail; }
 
        // export begin
@@ -145,12 +145,14 @@ fail:
 
 done:
 
-       free(nodes);
+       if(nodes)
+               { free(nodes); }
 
        for(size_t i = 0; edges && i < edge_count; ++i)
                { free(edges[i]); }
 
-       free(edges);
+       if(nodes)
+               { free(edges); }
 
        pthread_mutex_unlock(&(mesh->mesh_mutex));