From: Danny Al-Gaaf Date: Thu, 26 Jun 2014 02:40:09 +0000 (+0200) Subject: mount.ceph.c: fix strdup related memory leak X-Git-Tag: v0.83~32^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=605d1805692547a78beb9bf81ec8c0955b3c9274;p=ceph.git mount.ceph.c: fix strdup related memory leak 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 --- diff --git a/src/mount/mount.ceph.c b/src/mount/mount.ceph.c index 9d4e33b49ef5..e34cbd050145 100644 --- a/src/mount/mount.ceph.c +++ b/src/mount/mount.ceph.c @@ -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;