From patchwork Wed Sep 5 09:21:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Yong Wu X-Patchwork-Id: 1407271 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 02D4940B02 for ; Wed, 5 Sep 2012 09:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758431Ab2IEJVs (ORCPT ); Wed, 5 Sep 2012 05:21:48 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:48465 "EHLO e6.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758398Ab2IEJV2 (ORCPT ); Wed, 5 Sep 2012 05:21:28 -0400 Received: from /spool/local by e6.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Sep 2012 05:21:27 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e6.ny.us.ibm.com (192.168.1.106) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 5 Sep 2012 05:21:26 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id C668338C803B; Wed, 5 Sep 2012 05:21:25 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q859LPY3117112; Wed, 5 Sep 2012 05:21:25 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q859LPU4030069; Wed, 5 Sep 2012 06:21:25 -0300 Received: from us.ibm.com (f15.cn.ibm.com [9.115.122.154]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q859LLCk029822; Wed, 5 Sep 2012 06:21:22 -0300 Received: by us.ibm.com (sSMTP sendmail emulation); Wed, 5 Sep 2012 17:21:16 +0800 From: Zhi Yong Wu To: linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linuxram@linux.vnet.ibm.com, Zhi Yong Wu Subject: [PATCH v2 2/2] btrfs-progs: Fix up memory leakage Date: Wed, 5 Sep 2012 17:21:07 +0800 Message-Id: <1346836867-1060-3-git-send-email-wuzhy@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1346836867-1060-1-git-send-email-wuzhy@linux.vnet.ibm.com> References: <1346836867-1060-1-git-send-email-wuzhy@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12090509-1976-0000-0000-000010F19F9C Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Some code pathes forget to free memory on exit. Changelog from v1: Fix the variable is used uncorrectly. [Ram Pai] Signed-off-by: Zhi Yong Wu --- cmds-filesystem.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index e62c4fd..9c43d35 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -47,7 +47,7 @@ static const char * const cmd_df_usage[] = { static int cmd_df(int argc, char **argv) { - struct btrfs_ioctl_space_args *sargs; + struct btrfs_ioctl_space_args *sargs, *sargs_orig; u64 count = 0, i; int ret; int fd; @@ -65,7 +65,7 @@ static int cmd_df(int argc, char **argv) return 12; } - sargs = malloc(sizeof(struct btrfs_ioctl_space_args)); + sargs_orig = sargs = malloc(sizeof(struct btrfs_ioctl_space_args)); if (!sargs) return -ENOMEM; @@ -83,6 +83,7 @@ static int cmd_df(int argc, char **argv) } if (!sargs->total_spaces) { close(fd); + free(sargs); return 0; } @@ -92,6 +93,7 @@ static int cmd_df(int argc, char **argv) (count * sizeof(struct btrfs_ioctl_space_info))); if (!sargs) { close(fd); + free(sargs_orig); return -ENOMEM; }