From patchwork Mon Oct 24 02:43:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9391301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 13CCE60762 for ; Mon, 24 Oct 2016 02:44:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F391C287BB for ; Mon, 24 Oct 2016 02:44:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E70FA28C0B; Mon, 24 Oct 2016 02:44:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7407A287BB for ; Mon, 24 Oct 2016 02:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932431AbcJXCn7 (ORCPT ); Sun, 23 Oct 2016 22:43:59 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:39208 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932186AbcJXCn5 (ORCPT ); Sun, 23 Oct 2016 22:43:57 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="922782" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 24 Oct 2016 10:43:49 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id A9AC141B4BD6; Mon, 24 Oct 2016 10:43:43 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH 1/4] btrfs-progs: Fix memory leak in write_raid56_with_parity Date: Mon, 24 Oct 2016 10:43:32 +0800 Message-Id: <20161024024335.6770-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.1 MIME-Version: 1.0 X-yoursite-MailScanner-ID: A9AC141B4BD6.ADD87 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ebs and pointers are allocated, but if any of the allocation failed, we should free the allocated memory. Reported-by: David Sterba Resolves-Coverity-CID: 1296749 Signed-off-by: Qu Wenruo --- volumes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/volumes.c b/volumes.c index a7abd92..f687b0d 100644 --- a/volumes.c +++ b/volumes.c @@ -2120,8 +2120,11 @@ int write_raid56_with_parity(struct btrfs_fs_info *info, ebs = malloc(sizeof(*ebs) * multi->num_stripes); pointers = malloc(sizeof(*pointers) * multi->num_stripes); - if (!ebs || !pointers) + if (!ebs || !pointers) { + free(ebs); + free(pointers); return -ENOMEM; + } if (stripe_len > alloc_size) alloc_size = stripe_len;