From patchwork Thu Feb 4 02:17:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 76882 X-Patchwork-Delegate: ericvh@gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o142XQJI005596 for ; Thu, 4 Feb 2010 02:34:03 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1NcrWv-0007Nq-W7; Thu, 04 Feb 2010 02:33:17 +0000 Received: from sfi-mx-3.v28.ch3.sourceforge.com ([172.29.28.123] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1NcrWu-0007Mk-U2 for v9fs-developer@lists.sourceforge.net; Thu, 04 Feb 2010 02:33:16 +0000 X-ACL-Warn: Received: from e31.co.us.ibm.com ([32.97.110.149]) by sfi-mx-3.v28.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) id 1NcrWs-0004sQ-Ja for v9fs-developer@lists.sourceforge.net; Thu, 04 Feb 2010 02:33:16 +0000 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e31.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o14299Mr008794 for ; Wed, 3 Feb 2010 19:09:09 -0700 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o142HRwB181620 for ; Wed, 3 Feb 2010 19:17:27 -0700 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o142HQsn001714 for ; Wed, 3 Feb 2010 19:17:27 -0700 Received: from [127.0.0.1] (IBM-2AECC81F76A.beaverton.ibm.com [9.47.22.70]) by d03av03.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o142HPcp001670; Wed, 3 Feb 2010 19:17:26 -0700 Message-ID: <4B6A2E34.7010900@linux.vnet.ibm.com> Date: Wed, 03 Feb 2010 18:17:24 -0800 From: jvrao User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: v9fs-developer@lists.sourceforge.net X-Enigmail-Version: 0.96.0 X-Spam-Score: -3.0 (---) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -4.0 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [32.97.110.149 listed in list.dnswl.org] 1.0 AWL AWL: From: address is in the auto white-list X-Headers-End: 1NcrWs-0004sQ-Ja Cc: LTC filesystem development Subject: [V9fs-developer] [PATCH] Fix memory leak in v9fs_parse_options() X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Feb 2010 02:34:03 +0000 (UTC) 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; }