]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mount.ceph.c: fix strdup related memory leak
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 26 Jun 2014 02:40:09 +0000 (04:40 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 26 Jun 2014 02:40:09 +0000 (04:40 +0200)
CID 1219611 (#1 - 5): Resource leak (RESOURCE_LEAK)
 leaked_storage: Variable saw_name going out of scope
 leaks the storage it points to.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/mount/mount.ceph.c

index 9d4e33b49ef5785380e8724f54ac8cdfc6389920..e34cbd050145e5ac13f576298a165ba05527ab2b 100644 (file)
@@ -154,6 +154,7 @@ static char *parse_options(const char *data, int *filesys_flags)
                } else if (strncmp(data, "secretfile", 10) == 0) {
                        if (!value || !*value) {
                                printf("keyword secretfile found, but no secret file specified\n");
+                               free(saw_name);
                                return NULL;
                        }
 
@@ -186,9 +187,8 @@ static char *parse_options(const char *data, int *filesys_flags)
                        }
 
                        /* take a copy of the name, to be used for
-                          naming the keys that we add to kernel;
-                          ignore memleak as mount.ceph is
-                          short-lived */
+                          naming the keys that we add to kernel; */
+                       free(saw_name);
                        saw_name = strdup(value);
                        if (!saw_name) {
                                printf("out of memory.\n");
@@ -229,6 +229,7 @@ static char *parse_options(const char *data, int *filesys_flags)
                char secret_option[MAX_SECRET_OPTION_LEN];
                ret = get_secret_option(saw_secret, name, secret_option, sizeof(secret_option));
                if (ret < 0) {
+                       free(saw_name);
                        return NULL;
                } else {
                        if (pos) {
@@ -238,6 +239,7 @@ static char *parse_options(const char *data, int *filesys_flags)
                }
        }
 
+       free(saw_name);
        if (!out)
                return strdup(EMPTY_STRING);
        return out;