From patchwork Thu Sep 5 02:38:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 2853883 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 59190C0AB5 for ; Thu, 5 Sep 2013 02:40:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 63A8520145 for ; Thu, 5 Sep 2013 02:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BA9C20131 for ; Thu, 5 Sep 2013 02:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761963Ab3IECkk (ORCPT ); Wed, 4 Sep 2013 22:40:40 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:61818 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1760009Ab3IECki (ORCPT ); Wed, 4 Sep 2013 22:40:38 -0400 X-IronPort-AV: E=Sophos;i="4.90,843,1371052800"; d="scan'208";a="8417102" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 05 Sep 2013 10:37:28 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r852eZ3v014030 for ; Thu, 5 Sep 2013 10:40:35 +0800 Received: from localhost.localdomain ([10.167.226.111]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013090510382629-1242564 ; Thu, 5 Sep 2013 10:38:26 +0800 From: Gui Hecheng To: linux-btrfs@vger.kernel.org Cc: Gui Hecheng Subject: [PATCH 2/5] btrfs-progs:local variable memory freed Date: Thu, 5 Sep 2013 10:38:55 +0800 Message-Id: <1378348738-14451-3-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1378348738-14451-1-git-send-email-guihc.fnst@cn.fujitsu.com> References: <1378348738-14451-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/05 10:38:26, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/05 10:38:26, Serialize complete at 2013/09/05 10:38:26 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The local probe variable in is_ssd() freed upon unsuccessful return; The local dir_head list in make_image() freed upon unsuccessful return. Signed-off-by: Gui Hecheng --- mkfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mkfs.c b/mkfs.c index 1701783..415889e 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1024,6 +1024,8 @@ static int make_image(char *source_dir, struct btrfs_root *root, int out_fd) struct directory_name_entry dir_head; + struct directory_name_entry *dir_entry = NULL; + ret = lstat(source_dir, &root_st); if (ret) { fprintf(stderr, "unable to lstat the %s\n", source_dir); @@ -1043,6 +1045,12 @@ static int make_image(char *source_dir, struct btrfs_root *root, int out_fd) printf("Making image is completed.\n"); return 0; fail: + while (!list_empty(&dir_head.list)) { + dir_entry = list_entry(dir_head.list.next, + struct directory_name_entry, list); + list_del(&dir_entry->list); + free(dir_entry); + } fprintf(stderr, "Making image is aborted.\n"); return -1; } @@ -1161,8 +1169,10 @@ static int is_ssd(const char *file) /* Device number of this disk (possibly a partition) */ devno = blkid_probe_get_devno(probe); - if (!devno) + if (!devno) { + blkid_free_probe(probe); return 0; + } /* Get whole disk name (not full path) for this devno */ blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);