From patchwork Tue Sep 25 02:02:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 1501721 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2E3C4DF280 for ; Tue, 25 Sep 2012 02:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752276Ab2IYCCt (ORCPT ); Mon, 24 Sep 2012 22:02:49 -0400 Received: from e4.ny.us.ibm.com ([32.97.182.144]:49600 "EHLO e4.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751827Ab2IYCCr (ORCPT ); Mon, 24 Sep 2012 22:02:47 -0400 Received: from /spool/local by e4.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Sep 2012 22:02:46 -0400 Received: from d01relay04.pok.ibm.com (9.56.227.236) by e4.ny.us.ibm.com (192.168.1.104) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 24 Sep 2012 22:02:44 -0400 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8P22hgt191110; Mon, 24 Sep 2012 22:02:44 -0400 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8P22gmI024010; Mon, 24 Sep 2012 20:02:43 -0600 Received: from us.ibm.com (f15.cn.ibm.com [9.115.122.154]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q8P22c63023798; Mon, 24 Sep 2012 20:02:39 -0600 Received: by us.ibm.com (sSMTP sendmail emulation); Tue, 25 Sep 2012 10:02:28 +0800 From: zwu.kernel@gmail.com To: linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jbacik@fusionio.com, dave@jikos.cz, linuxram@linux.vnet.ibm.com, Zhi Yong Wu Subject: [PATCH v2 2/2] btrfs-progs: Fix up memory leakage Date: Tue, 25 Sep 2012 10:02:16 +0800 Message-Id: <1348538536-29838-3-git-send-email-zwu.kernel@gmail.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1348538536-29838-1-git-send-email-zwu.kernel@gmail.com> References: <1348538536-29838-1-git-send-email-zwu.kernel@gmail.com> x-cbid: 12092502-3534-0000-0000-00000D11017D Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Zhi Yong Wu 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; }