From patchwork Sat May 25 14:16:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 2613551 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 76185DF2A2 for ; Sat, 25 May 2013 14:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756431Ab3EYOQx (ORCPT ); Sat, 25 May 2013 10:16:53 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:33737 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756178Ab3EYOQw (ORCPT ); Sat, 25 May 2013 10:16:52 -0400 Received: by mail-wg0-f53.google.com with SMTP id m15so3238963wgh.8 for ; Sat, 25 May 2013 07:16:51 -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:x-mailer:in-reply-to:references; bh=HMKkcyxjN1c2zEypDOkXyAPnyMW6s5h6d6b7dKFlzoc=; b=0sZlPgCwsFcZdqiOyJd1gbyIKPtYgYcd2V5kJmXO4AOHBO0dUycLuy+8cdFbz1YWtV WTSbooLZVBEeyt94/2hoeNvBO5u3Nu4vxO5KpMG+pjj54lSSWpIYP5pBLueSrO9gkqcq Svo9k9X0yRqpfATF/UjlP9zt1gynI/FDu7bI9p56jIlis5++tJ0XNOeAjeSvBFYvJk3e RnaPJ8a182J5mLv5+LY4RfCLBEhNDdR8Tkjz8niPi9aZl38XBppJG+RyHPRZnqQrLmAl iW/dcWGx/jmMHMKhSorsYjeoqK1omCfTksaNd0xPgeE9CkPuSfph/9Apnkp2QjRLNFrz rd4Q== X-Received: by 10.180.189.136 with SMTP id gi8mr2552483wic.11.1369491411628; Sat, 25 May 2013 07:16:51 -0700 (PDT) Received: from storm-desktop.lan (bl5-172-39.dsl.telepac.pt. [82.154.172.39]) by mx.google.com with ESMTPSA id m3sm5329322wij.5.2013.05.25.07.16.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 25 May 2013 07:16:51 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs-progs: Add missing free() against fs_info->super_copy Date: Sat, 25 May 2013 15:16:39 +0100 Message-Id: <1369491399-6769-2-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1369491399-6769-1-git-send-email-fdmanana@gmail.com> References: <1369491399-6769-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There was a missing free() call against fs_info->super_copy in several places: 1) close_ctree() 2) open_ctree_broken() on failure 3) __open_ctree_fd() on failure Signed-off-by: Filipe David Borba Manana --- btrfs-find-root.c | 5 +++-- disk-io.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/btrfs-find-root.c b/btrfs-find-root.c index 810d835..b2690d1 100644 --- a/btrfs-find-root.c +++ b/btrfs-find-root.c @@ -94,7 +94,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device) struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root)); - struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); + struct btrfs_fs_info *fs_info = calloc(1, sizeof(*fs_info)); int ret; struct btrfs_super_block *disk_super; struct btrfs_fs_devices *fs_devices = NULL; @@ -115,7 +115,6 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device) goto out; } - memset(fs_info, 0, sizeof(*fs_info)); fs_info->super_copy = calloc(1, BTRFS_SUPER_INFO_SIZE); fs_info->tree_root = tree_root; fs_info->extent_root = extent_root; @@ -228,6 +227,8 @@ out: free(chunk_root); free(dev_root); free(csum_root); + if (fs_info) + free(fs_info->super_copy); free(fs_info); return NULL; } diff --git a/disk-io.c b/disk-io.c index 21b410d..eea7453 100644 --- a/disk-io.c +++ b/disk-io.c @@ -812,7 +812,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root)); - struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); + struct btrfs_fs_info *fs_info = calloc(1, sizeof(*fs_info)); int ret; struct btrfs_super_block *disk_super; struct btrfs_fs_devices *fs_devices = NULL; @@ -840,7 +840,6 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, goto out; } - memset(fs_info, 0, sizeof(*fs_info)); fs_info->super_copy = calloc(1, BTRFS_SUPER_INFO_SIZE); fs_info->tree_root = tree_root; fs_info->extent_root = extent_root; @@ -1039,6 +1038,8 @@ out: free(chunk_root); free(dev_root); free(csum_root); + if (fs_info) + free(fs_info->super_copy); free(fs_info); return NULL; } @@ -1347,6 +1348,7 @@ int close_ctree(struct btrfs_root *root) free(fs_info->chunk_root); free(fs_info->dev_root); free(fs_info->csum_root); + free(fs_info->super_copy); free(fs_info); return 0;