diff mbox

[V9fs-developer] Fix memory leak in v9fs_parse_options()

Message ID 4B6A2E34.7010900@linux.vnet.ibm.com (mailing list archive)
State Superseded, archived
Delegated to: Eric Van Hensbergen
Headers show

Commit Message

jvrao Feb. 4, 2010, 2:17 a.m. UTC
None
diff mbox

Patch

diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index cf62b05..3432dcb 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -84,7 +84,7 @@  static const match_table_t tokens = {
 
 static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 {
-       char *options;
+       char *options, *tmp_options;
        substring_t args[MAX_OPT_ARGS];
        char *p;
        int option = 0;
@@ -102,9 +102,14 @@  static int v9fs_parse_options(struct v9fs_session_info *v9s
        if (!opts)
                return 0;
 
-       options = kstrdup(opts, GFP_KERNEL);
-       if (!options)
-               goto fail_option_alloc;
+       tmp_options = kstrdup(opts, GFP_KERNEL);
+       options = tmp_options;
+
+       if (!options) {
+               P9_DPRINTK(P9_DEBUG_ERROR,
+                          "failed to allocate copy of option argument\n");
+               return -ENOMEM;
+       }
 
        while ((p = strsep(&options, ",")) != NULL) {
                int token;
@@ -159,8 +164,12 @@  static int v9fs_parse_options(struct v9fs_session_info *v9s
                        break;
                case Opt_cache:
                        s = match_strdup(&args[0]);
-                       if (!s)
-                               goto fail_option_alloc;
+                       if (!s) {
+                               P9_DPRINTK(P9_DEBUG_ERROR,
+                                       "failed to dup Opt_cache arg.\n");
+                               kfree(tmp_options);
+                               return -ENOMEM;
+                       }
 
                        if (strcmp(s, "loose") == 0)
                                v9ses->cache = CACHE_LOOSE;
@@ -173,8 +182,12 @@  static int v9fs_parse_options(struct v9fs_session_info *v9s
 
                case Opt_access:
                        s = match_strdup(&args[0]);
-                       if (!s)
-                               goto fail_option_alloc;
+                       if (!s) {
+                               P9_DPRINTK(P9_DEBUG_ERROR,
+                                       "failed to dup Opt_access arg.\n");
+                               kfree(tmp_options);
+                               return -ENOMEM;
+                       }
 
                        v9ses->flags &= ~V9FS_ACCESS_MASK;
                        if (strcmp(s, "user") == 0)
@@ -194,13 +207,8 @@  static int v9fs_parse_options(struct v9fs_session_info *v9s
                        continue;
                }
        }
-       kfree(options);
+       kfree(tmp_options);
        return ret;
-
-fail_option_alloc:
-       P9_DPRINTK(P9_DEBUG_ERROR,
-                  "failed to allocate copy of option argument\n");
-       return -ENOMEM;
 }