]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
src/rrd_daemon.c: fix Coverity CIDs#32420,#26530 Resource leak
authorMarek Schimara <Marek.Schimara@bull.net>
Wed, 15 Jun 2016 09:09:34 +0000 (11:09 +0200)
committerMarek Schimara <Marek.Schimara@bull.net>
Thu, 23 Jun 2016 14:32:32 +0000 (16:32 +0200)
        CWE-404 / https://cwe.mitre.org/data/definitions/404.html

src/rrd_daemon.c

index b1a7c599e7eacbe702292100c95fd0caa65a49ff..32d8a240533cfb5abeb5ac54db77935fcbc2639f 100644 (file)
@@ -3279,20 +3279,21 @@ static int open_listen_socket_unix (const listen_socket_t *sock) /* {{{ */
   }
 
   dir = strdup(dirname(path_copy));
+  free(path_copy);
   if (rrd_mkdir_p(dir, 0777) != 0)
   {
     fprintf(stderr, "Failed to create socket directory '%s': %s\n",
         dir, rrd_strerror(errno));
+    free(dir);
     return (-1);
   }
 
-  free(path_copy);
-
   temp = (listen_socket_t *) rrd_realloc (listen_fds,
       sizeof (listen_fds[0]) * (listen_fds_num + 1));
   if (temp == NULL)
   {
     fprintf (stderr, "rrdcached: open_listen_socket_unix: realloc failed.\n");
+    free(dir);
     return (-1);
   }
   listen_fds = temp;
@@ -3303,6 +3304,7 @@ static int open_listen_socket_unix (const listen_socket_t *sock) /* {{{ */
   {
     fprintf (stderr, "rrdcached: unix socket(2) failed: %s\n",
              rrd_strerror(errno));
+    free(dir);
     return (-1);
   }
 
@@ -3322,6 +3324,7 @@ static int open_listen_socket_unix (const listen_socket_t *sock) /* {{{ */
     fprintf (stderr, "rrdcached: bind(%s) failed: %s.\n",
              path, rrd_strerror(errno));
     close (fd);
+    free(dir);
     return (-1);
   }
 
@@ -3349,6 +3352,7 @@ static int open_listen_socket_unix (const listen_socket_t *sock) /* {{{ */
              path, rrd_strerror(errno));
     close (fd);
     unlink (path);
+    free(dir);
     return (-1);
   }
 
@@ -3357,6 +3361,7 @@ static int open_listen_socket_unix (const listen_socket_t *sock) /* {{{ */
   listen_fds[listen_fds_num].addr = strdup(path);
   listen_fds_num++;
 
+  free(dir);
   return (0);
 } /* }}} int open_listen_socket_unix */