From patchwork Sat Apr 19 11:12:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rakesh Pandit X-Patchwork-Id: 4019751 X-Patchwork-Delegate: dave@jikos.cz 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A748E9F2BA for ; Sat, 19 Apr 2014 11:12:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CFAB02026F for ; Sat, 19 Apr 2014 11:12:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8ACC42026C for ; Sat, 19 Apr 2014 11:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751332AbaDSLMI (ORCPT ); Sat, 19 Apr 2014 07:12:08 -0400 Received: from nbl-ex10-fe02.nebula.fi ([188.117.32.122]:25166 "EHLO ex10.nebula.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751077AbaDSLMH (ORCPT ); Sat, 19 Apr 2014 07:12:07 -0400 Received: from hercules.tuxera.com (88.195.159.123) by ex10.nebula.fi (188.117.32.115) with Microsoft SMTP Server (TLS) id 14.3.174.1; Sat, 19 Apr 2014 14:12:04 +0300 Date: Sat, 19 Apr 2014 14:12:03 +0300 From: Rakesh Pandit To: Subject: [PATCH] Btrfs-progs: fi-disk_usage: free memory if realloc fails Message-ID: <20140419111201.GA4762@hercules.tuxera.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [88.195.159.123] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Lets not assign *info_ptr to 0 before calling free on it and lose track of already allocated memory if realloc fails in add_info_to_list. Lets call free first. Signed-off-by: Rakesh Pandit --- cmds-fi-disk_usage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds-fi-disk_usage.c b/cmds-fi-disk_usage.c index 2bd591d..cd71c8d 100644 --- a/cmds-fi-disk_usage.c +++ b/cmds-fi-disk_usage.c @@ -104,6 +104,7 @@ static int add_info_to_list(struct chunk_info **info_ptr, struct chunk_info *res = realloc(*info_ptr, size); if (!res) { + free(*info_ptr); fprintf(stderr, "ERROR: not enough memory\n"); return -1; } @@ -224,7 +225,6 @@ static int load_chunk_info(int fd, if (add_info_to_list(info_ptr, info_count, item)) { *info_ptr = 0; - free(*info_ptr); return -100; }