From patchwork Fri Nov 7 01:08:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorgen Lundman X-Patchwork-Id: 407978 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E76B814012A for ; Fri, 7 Nov 2014 17:26:39 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 241F04BACB; Fri, 7 Nov 2014 07:26:33 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QthcmV7S4As2; Fri, 7 Nov 2014 07:26:32 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2C7054BAD4; Fri, 7 Nov 2014 07:26:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9286A4BA80 for ; Fri, 7 Nov 2014 02:18:13 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ysir0hIJ2r2e for ; Fri, 7 Nov 2014 02:18:13 +0100 (CET) X-Greylist: delayed 556 seconds by postgrey-1.32 at theia; Fri, 07 Nov 2014 02:18:09 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.lundman.net (mail.lundman.net [210.157.1.114]) by theia.denx.de (Postfix) with ESMTPS id 2C5344BA7E for ; Fri, 7 Nov 2014 02:18:09 +0100 (CET) Received: from localhost (solaris11 [127.0.0.1]) by mail.lundman.net (Postfix) with ESMTP id B01B492B1D; Fri, 7 Nov 2014 10:08:40 +0900 (JST) X-DKIM: OpenDKIM Filter v2.2.1 mail.lundman.net B01B492B1D DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=lundman.net; s=dkim; t=1415322520; bh=JQ1KTwADf4KtuqexURBoW3cC3qLrCVrPVCdAYWaLvyo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=EASnnAb9f4Y+t+G0MPM2kBkE9qxHUJfNbTQFzFfE6AK+qQycjJbzI/b3vGtzoG4dn nKNqupmtKv20HrjVsyYxHoUS0PZajnGYcns73wvEl+HXPSJMzLToRD0Wk2JgsUj1p6 P/JTqMDAhPbbYnvf/l1pgfQ9/m4b1/Y1GSTNfeYA= X-Virus-Scanned: amavisd-new at lundman.net Received: from mail.lundman.net ([127.0.0.1]) by localhost (mail.lundman.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Bx17AIL9DUtw; Fri, 7 Nov 2014 10:08:40 +0900 (JST) Received: from shinken.internal-gmo (shinken.interq.or.jp [210.172.146.228]) by mail.lundman.net (Postfix) with ESMTPA id 2645192B17; Fri, 7 Nov 2014 10:08:40 +0900 (JST) From: Jorgen Lundman To: u-boot@lists.denx.de Date: Fri, 7 Nov 2014 10:08:35 +0900 Message-Id: <1415322515-86220-1-git-send-email-lundman@lundman.net> X-Mailer: git-send-email 2.0.0 In-Reply-To: <20141106123654.0F1C638334C@gemini.denx.de> References: <20141106123654.0F1C638334C@gemini.denx.de> X-Mailman-Approved-At: Fri, 07 Nov 2014 07:26:25 +0100 Cc: Jorgen Lundman Subject: [U-Boot] [PATCH v1] ZFS: Clean up cppcheck warnings where relevant, leaked memory etc X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de In a message from Wolfgang Denk highlighting warnings from cppcheck, the patch will address those that are correctly diagnosed. Some are false-positives: > [fs/zfs/zfs.c:937]: (error) Memory leak: l dmu_read() allocates "l" if successful, so error-case should not free it. > [fs/zfs/zfs.c:1141]: (error) Memory leak: dnbuf dmu_read() allocates "dnbuf" if successful, so error-case should not free it. > [fs/zfs/zfs.c:1372]: (error) Memory leak: osp zio_read() allocates "osp" if successful, so error-case should not free it. > [fs/zfs/zfs.c:1726]: (error) Memory leak: nvlist int_zfs_fetch_nvlist() allocates "nvlist" if successful, so error-case should not free it. Signed-off-by: Jorgen Lundman --- fs/zfs/zfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c index 818d3d9..fb2b3ee 100644 --- a/fs/zfs/zfs.c +++ b/fs/zfs/zfs.c @@ -736,7 +736,7 @@ zap_hash(uint64_t salt, const char *name) uint64_t crc = salt; if (table[128] == 0) { - uint64_t *ct; + uint64_t *ct = NULL; int i, j; for (i = 0; i < 256; i++) { for (ct = table + i, *ct = i, j = 8; j > 0; j--) @@ -1060,6 +1060,7 @@ zap_lookup(dnode_end_t *zap_dnode, char *name, uint64_t *val, } printf("unknown ZAP type\n"); + free(zapbuf); return ZFS_ERR_BAD_FS; } @@ -1094,6 +1095,7 @@ zap_iterate(dnode_end_t *zap_dnode, return ret; } printf("unknown ZAP type\n"); + free(zapbuf); return 0; } @@ -1865,6 +1867,7 @@ zfs_mount(device_t dev) ubbest = malloc(sizeof(*ubbest)); if (!ubbest) { + free(ub_array); zfs_unmount(data); return 0; } @@ -1953,6 +1956,7 @@ zfs_mount(device_t dev) if (err) { printf("couldn't zio_read object directory\n"); zfs_unmount(data); + free(osp); free(ubbest); return 0; } @@ -2052,6 +2056,9 @@ zfs_open(struct zfs_file *file, const char *fsfilename) hdrsize = SA_HDR_SIZE(((sa_hdr_phys_t *) sahdrp)); file->size = *(uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET); + if ((data->dnode.dn.dn_bonuslen == 0) && + (data->dnode.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR)) + free(sahdrp); } else { file->size = zfs_to_cpu64(((znode_phys_t *) DN_BONUS(&data->dnode.dn))->zp_size, data->dnode.endian); }