From b0f7726931e9339e91b8d49941626f015015bd98 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 14 Aug 2017 22:42:14 +0200 Subject: [PATCH] Fix errors found by Clang's static analyzer. --- examples/manynodes.c | 3 +++ src/conf.c | 2 +- src/meshlink.c | 1 + src/net.c | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/manynodes.c b/examples/manynodes.c index a0781ba6..61b5ece5 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -20,6 +20,7 @@ #include #include +#include static int n = 10; static meshlink_handle_t **mesh; @@ -77,6 +78,8 @@ static void linkmesh() { } static bool exportmeshgraph(const char *path) { + assert(path); + struct stat ps; int psr = stat(path, &ps); diff --git a/src/conf.c b/src/conf.c index ceca04db..8bfa855d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -432,7 +432,7 @@ bool modify_config_file(struct meshlink_handle *mesh, const char *name, const ch } // We found the key and the value. We already added it at the top, so ignore this one. - if(sep[1] == '=' && sep[2] == ' ' && !strcmp(sep + 3, value)) + if(value && sep[1] == '=' && sep[2] == ' ' && !strcmp(sep + 3, value)) continue; // We found the key but with a different value, delete it if wanted. diff --git a/src/meshlink.c b/src/meshlink.c index f038043f..90cdf0db 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1946,6 +1946,7 @@ char *meshlink_export(meshlink_handle_t *mesh) { if(fread(buf + len - fsize - 1, fsize, 1, f) != 1) { logger(mesh, MESHLINK_DEBUG, "Error reading from %s: %s\n", filename, strerror(errno)); fclose(f); + free(buf); meshlink_errno = MESHLINK_ESTORAGE; pthread_mutex_unlock(&(mesh->mesh_mutex)); return NULL; diff --git a/src/net.c b/src/net.c index 8e5c2c18..c0ed9849 100644 --- a/src/net.c +++ b/src/net.c @@ -67,7 +67,7 @@ void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) /* If the node is not reachable anymore but we remember it had an edge to us, clean it up */ - if(report && !c->node->status.reachable) { + if(report && c->node && !c->node->status.reachable) { edge_t *e; e = lookup_edge(c->node, mesh->self); if(e) { -- 2.39.5