]> git.meshlink.io Git - meshlink/commitdiff
Fix resource leaks found by cppcheck.
authorGuus Sliepen <guus@meshlink.io>
Sun, 15 Nov 2015 16:18:37 +0000 (17:18 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sun, 25 Jun 2017 08:50:37 +0000 (10:50 +0200)
src/conf.c
src/ed25519/seed.c
src/meshlink.c

index 8acb64b9cea55fffc1fad869d526a2b4c91353bb..ef595efca958f8cdb22ad240f41fb4f09864f0d1 100644 (file)
@@ -333,30 +333,26 @@ bool write_config_file(const struct splay_tree_t *config_tree, const char *fname
 
        for splay_each(config_t, cnf, config_tree)
        {
-               if(fwrite(cnf->variable, sizeof(char), strlen(cnf->variable), fp) < strlen(cnf->variable)) {
-                       logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
-                       return false;
-               }
+               if(fwrite(cnf->variable, sizeof(char), strlen(cnf->variable), fp) < strlen(cnf->variable))
+                       goto error;
 
-               if(fwrite(" = ", sizeof(char), 3, fp) < 3) {
-                       logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
-                       return false;
-               }
+               if(fwrite(" = ", sizeof(char), 3, fp) < 3)
+                       goto error;
 
-               if(fwrite(cnf->value, sizeof(char), strlen(cnf->value), fp) < strlen(cnf->value)) {
-                       logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
-                       return false;
-               }
+               if(fwrite(cnf->value, sizeof(char), strlen(cnf->value), fp) < strlen(cnf->value))
+                       goto error;
 
-               if(fwrite("\n", sizeof(char), 1, fp) < 1) {
-                       logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
-                       return false;
-               }
+               if(fwrite("\n", sizeof(char), 1, fp) < 1)
+                       goto error;
        }
 
        fclose(fp);
-
        return true;
+
+error:
+       logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
+       fclose(fp);
+       return false;
 }
 
 bool read_server_config(meshlink_handle_t *mesh) {
index dda3ccb2368af6afd77b1f3e5dc52fca47f9d812..15f41c0a8d96b458265120789682770ad1093a87 100644 (file)
@@ -30,8 +30,10 @@ int ed25519_create_seed(unsigned char *seed) {
         return 1;
     }
 
-    if(fread(seed, 32, 1, f) != 1)
+    if(fread(seed, 32, 1, f) != 1) {
+           fclose(f);
            return 1;
+    }
 
     fclose(f);
 #endif
index 446bc522df9cb13556ede9d946965fb91d9c959a..68286d29046aa9e6477e012f5075f0a643f9e2d3 100644 (file)
@@ -2042,7 +2042,6 @@ meshlink_edge_t **meshlink_get_all_edges_state(meshlink_handle_t *mesh, meshlink
                *nmemb = result_size;
        } else {
                *nmemb = 0;
-               free(result);
                meshlink_errno = MESHLINK_ENOMEM;
        }