From patchwork Mon Oct 19 11:37:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 7435221 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F13C39F36A for ; Mon, 19 Oct 2015 11:47:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2F124206E0 for ; Mon, 19 Oct 2015 11:47:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C610206DF for ; Mon, 19 Oct 2015 11:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751079AbbJSLq4 (ORCPT ); Mon, 19 Oct 2015 07:46:56 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:36694 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750839AbbJSLqz (ORCPT ); Mon, 19 Oct 2015 07:46:55 -0400 Received: by pacfv9 with SMTP id fv9so93708317pac.3 for ; Mon, 19 Oct 2015 04:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T91eOL1N4OQBcg/YYSWQy/bGKSppY9kz56OuPk4DlCM=; b=Nvs0MwakoV2TE3CTIfZTrqGwcFpdTawiATWCscXHe35ZVtSKfd6rOnb226864Tbqwe M+ZTlpqy7wcUKDuyPg2QGu5IQ/K8IHcU6szi0AvTj5Od77VpoQR/JXZuIIV9ZJiE+MIH 0odCLj2SorOosvkuR95IDKgRu9fKboZJm+OM+Nw6KkAT0ARPwXfqSwRW+pmoK2G1Rhi/ p/0b/FhVCnNWrBgB4o3wympvt1dPMnIiiV+Rj2xJ5DiI/Tc5gV71We09e8FW1/MMHuFf uOuaZ7xwmblf08o8OMl6eNpXqFdRrr3j4iui5hnCzHSWAKSSne/upZEKgvVFVw4yDv6G 1DSQ== X-Received: by 10.68.100.226 with SMTP id fb2mr34410175pbb.92.1445255215226; Mon, 19 Oct 2015 04:46:55 -0700 (PDT) Received: from localhost ([128.199.137.77]) by smtp.gmail.com with ESMTPSA id pn8sm9093053pbb.16.2015.10.19.04.46.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 04:46:54 -0700 (PDT) From: Eryu Guan To: linux-btrfs@vger.kernel.org Cc: Eryu Guan Subject: [PATCH 07/10] btrfs-progs: fix memory leak on error path Date: Mon, 19 Oct 2015 19:37:57 +0800 Message-Id: <1445254680-11102-8-git-send-email-guaneryu@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1445254680-11102-1-git-send-email-guaneryu@gmail.com> References: <1445254680-11102-1-git-send-email-guaneryu@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 dev_scans and t_scans should be freed on malloc error. Signed-off-by: Eryu Guan --- chunk-recover.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/chunk-recover.c b/chunk-recover.c index 1fb04f7..c727f0f 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -847,11 +847,16 @@ static int scan_devices(struct recover_control *rc) if (!dev_scans) return -ENOMEM; t_scans = (pthread_t *)malloc(sizeof(pthread_t) * devnr); - if (!t_scans) + if (!t_scans) { + free(dev_scans); return -ENOMEM; + } t_rets = (long *)malloc(sizeof(long) * devnr); - if (!t_rets) + if (!t_rets) { + free(dev_scans); + free(t_scans); return -ENOMEM; + } list_for_each_entry(dev, &rc->fs_devices->devices, dev_list) { fd = open(dev->name, O_RDONLY);