]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
ZFS: Clean up cppcheck warnings where relevant, leaked memory etc
authorJorgen Lundman <lundman@lundman.net>
Fri, 7 Nov 2014 01:08:35 +0000 (10:08 +0900)
committerTom Rini <trini@ti.com>
Mon, 10 Nov 2014 21:25:27 +0000 (16:25 -0500)
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 <lundman@lundman.net>
fs/zfs/zfs.c

index 818d3d926d2a3a349ac2e96bef28bc93e24b49cf..fb2b3ee089ecadb8c82cb35bc7912ffce9cbf65d 100644 (file)
@@ -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);
        }