Skip to content

Commit

Permalink
9p: fix memory leak in v9fs_parse_options()
Browse files Browse the repository at this point in the history
If match_strdup() fail this function exits without freeing the options string.

Signed-off-by: Venkateswararao Jujjuri <[email protected]>
Sigend-off-by: Eric Van Hensbergen <[email protected]>
  • Loading branch information
ericvh committed Feb 8, 2010
1 parent fb78610 commit bf2d29c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions fs/9p/v9fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
return 0;

tmp_options = kstrdup(opts, GFP_KERNEL);
if (!tmp_options)
if (!tmp_options) {
ret = -ENOMEM;
goto fail_option_alloc;
}
options = tmp_options;

while ((p = strsep(&options, ",")) != NULL) {
Expand Down Expand Up @@ -160,8 +162,12 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
break;
case Opt_cache:
s = match_strdup(&args[0]);
if (!s)
goto fail_option_alloc;
if (!s) {
ret = -ENOMEM;
P9_DPRINTK(P9_DEBUG_ERROR,
"problem allocating copy of cache arg\n");
goto free_and_return;
}

if (strcmp(s, "loose") == 0)
v9ses->cache = CACHE_LOOSE;
Expand All @@ -174,8 +180,12 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)

case Opt_access:
s = match_strdup(&args[0]);
if (!s)
goto fail_option_alloc;
if (!s) {
ret = -ENOMEM;
P9_DPRINTK(P9_DEBUG_ERROR,
"problem allocating copy of access arg\n");
goto free_and_return;
}

v9ses->flags &= ~V9FS_ACCESS_MASK;
if (strcmp(s, "user") == 0)
Expand All @@ -196,13 +206,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
}
}

free_and_return:
kfree(tmp_options);
return ret;

fail_option_alloc:
P9_DPRINTK(P9_DEBUG_ERROR,
"failed to allocate copy of option argument\n");
return -ENOMEM;
return ret;
}

/**
Expand Down

0 comments on commit bf2d29c

Please sign in to comment.