]> git.meshlink.io Git - meshlink/commitdiff
Fix errors found by Clang's static analyzer.
authorGuus Sliepen <guus@meshlink.io>
Thu, 26 Sep 2019 20:43:45 +0000 (22:43 +0200)
committerGuus Sliepen <guus@meshlink.io>
Thu, 26 Sep 2019 20:43:45 +0000 (22:43 +0200)
src/devtools.c
src/discovery.c
src/meshlink.c
src/net.c
src/net_setup.c

index 629d90bd3c049f9858741c4e31a33fd2808a7c51..47f18bc61f670f00a69d06cfc1b289ef5d514bfa 100644 (file)
@@ -61,7 +61,7 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e
 
        // if result is smaller than edges, we have to dealloc all the excess devtool_edge_t
        if((size_t)result_size > *nmemb) {
-               result = realloc(edges, result_size * sizeof(*result));
+               result = xrealloc(edges, result_size * sizeof(*result));
        } else {
                result = edges;
        }
@@ -93,7 +93,7 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e
                }
 
                // shrink result to the actual amount of memory used
-               result = realloc(result, n * sizeof(*result));
+               result = xrealloc(result, n * sizeof(*result));
                *nmemb = n;
        } else {
                *nmemb = 0;
index 72ff8bc5b5c6b57adae057e4c6db0fdb8d12d7f2..ae2cf895d7d44c228b31319c3fa944d49189e7df 100644 (file)
@@ -221,7 +221,6 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI
                        pthread_mutex_lock(&(mesh->mesh_mutex));
 
                        node_name += 1;
-                       node_fp += 1;
 
                        meshlink_node_t *node = meshlink_get_node(mesh, node_name);
 
index 0826487674f2467d24c8d201968e8e815b1a702b..c4822cdfd07bc6c1a5ab27e87a4bffba984b825d 100644 (file)
@@ -846,6 +846,7 @@ static struct timeval idle(event_loop_t *loop, void *data) {
 // Get our local address(es) by simulating connecting to an Internet host.
 static void add_local_addresses(meshlink_handle_t *mesh) {
        struct sockaddr_storage sn;
+       sn.ss_family = AF_UNKNOWN;
        socklen_t sl = sizeof(sn);
 
        // IPv4 example.org
@@ -1013,13 +1014,14 @@ meshlink_open_params_t *meshlink_open_params_init(const char *confbase, const ch
 
        if(!name || !*name) {
                logger(NULL, MESHLINK_ERROR, "No name given!\n");
-               //return NULL;
-       } else { //check name only if there is a name != NULL
-               if(!check_id(name)) {
-                       logger(NULL, MESHLINK_ERROR, "Invalid name given!\n");
-                       meshlink_errno = MESHLINK_EINVAL;
-                       return NULL;
-               }
+               meshlink_errno = MESHLINK_EINVAL;
+               return NULL;
+       };
+
+       if(!check_id(name)) {
+               logger(NULL, MESHLINK_ERROR, "Invalid name given!\n");
+               meshlink_errno = MESHLINK_EINVAL;
+               return NULL;
        }
 
        if(devclass < 0 || devclass >= DEV_CLASS_COUNT) {
@@ -2192,10 +2194,10 @@ bool meshlink_set_port(meshlink_handle_t *mesh, int port) {
                meshlink_errno = MESHLINK_ESTORAGE;
                free_node(mesh->self);
                mesh->self = NULL;
+               goto done;
        } else if(!setup_network(mesh)) {
                meshlink_errno = MESHLINK_ENETWORK;
-       } else {
-               rval = true;
+               goto done;
        }
 
        /* Rebuild our own list of recent addresses */
@@ -2205,9 +2207,7 @@ bool meshlink_set_port(meshlink_handle_t *mesh, int port) {
        /* Write meshlink.conf with the updated port number */
        write_main_config_files(mesh);
 
-       if(!config_sync(mesh, "current")) {
-               return false;
-       }
+       rval = config_sync(mesh, "current");
 
 done:
        pthread_mutex_unlock(&(mesh->mesh_mutex));
index b5705a471b198dde06bed1792d0208a835490a1d..9dd42dd5acf678eeffd08e28f93a96404760b044 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -40,6 +40,7 @@ static inline int min(int a, int b) {
 #endif
 
 static const int default_timeout = 5;
+static const int default_interval = 60;
 
 /*
   Terminate a connection:
@@ -113,6 +114,7 @@ static void timeout_handler(event_loop_t *loop, void *data) {
 
        for list_each(connection_t, c, mesh->connections) {
                int pingtimeout = c->node ? mesh->dev_class_traits[c->node->devclass].pingtimeout : default_timeout;
+               int pinginterval = c->node ? mesh->dev_class_traits[c->node->devclass].pinginterval : default_interval;
 
                // Also make sure that if outstanding key requests for the UDP counterpart of a connection has timed out, we restart it.
                if(c->node) {
@@ -125,7 +127,7 @@ static void timeout_handler(event_loop_t *loop, void *data) {
                        if(c->status.active) {
                                if(c->status.pinged) {
                                        logger(mesh, MESHLINK_INFO, "%s didn't respond to PING in %ld seconds", c->name, (long)mesh->loop.now.tv_sec - c->last_ping_time);
-                               } else if(c->last_ping_time + mesh->dev_class_traits[c->node->devclass].pinginterval <= mesh->loop.now.tv_sec) {
+                               } else if(c->last_ping_time + pinginterval <= mesh->loop.now.tv_sec) {
                                        send_ping(mesh, c);
                                        continue;
                                } else {
index fc6b3c97298551f3f7c1b02e23a601b20e67061c..e79550327d1ec5bf15cdc79a4f03a4bda6a3f5ad 100644 (file)
@@ -53,7 +53,7 @@ static bool node_get_config(meshlink_handle_t *mesh, node_t *n, config_t *config
        const char *name;
        uint32_t len = packmsg_get_str_raw(in, &name);
 
-       if(len != strlen(n->name) || strncmp(name, n->name, len)) {
+       if(len != strlen(n->name) || !name || strncmp(name, n->name, len)) {
                config_free(config);
                return false;
        }