Commit e183de0d3efccd77b4a7b9d1395a9f29bba68e26
Committed by
Tom Rini
1 parent
6c5f4aef02
Exists in
v2017.01-smarct4x
and in
37 other branches
ZFS: Clean up cppcheck warnings where relevant, leaked memory etc
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>
Showing 1 changed file with 8 additions and 1 deletions Side-by-side Diff
fs/zfs/zfs.c
... | ... | @@ -736,7 +736,7 @@ |
736 | 736 | uint64_t crc = salt; |
737 | 737 | |
738 | 738 | if (table[128] == 0) { |
739 | - uint64_t *ct; | |
739 | + uint64_t *ct = NULL; | |
740 | 740 | int i, j; |
741 | 741 | for (i = 0; i < 256; i++) { |
742 | 742 | for (ct = table + i, *ct = i, j = 8; j > 0; j--) |
... | ... | @@ -1060,6 +1060,7 @@ |
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | printf("unknown ZAP type\n"); |
1063 | + free(zapbuf); | |
1063 | 1064 | return ZFS_ERR_BAD_FS; |
1064 | 1065 | } |
1065 | 1066 | |
... | ... | @@ -1094,6 +1095,7 @@ |
1094 | 1095 | return ret; |
1095 | 1096 | } |
1096 | 1097 | printf("unknown ZAP type\n"); |
1098 | + free(zapbuf); | |
1097 | 1099 | return 0; |
1098 | 1100 | } |
1099 | 1101 | |
... | ... | @@ -1865,6 +1867,7 @@ |
1865 | 1867 | |
1866 | 1868 | ubbest = malloc(sizeof(*ubbest)); |
1867 | 1869 | if (!ubbest) { |
1870 | + free(ub_array); | |
1868 | 1871 | zfs_unmount(data); |
1869 | 1872 | return 0; |
1870 | 1873 | } |
... | ... | @@ -1953,6 +1956,7 @@ |
1953 | 1956 | if (err) { |
1954 | 1957 | printf("couldn't zio_read object directory\n"); |
1955 | 1958 | zfs_unmount(data); |
1959 | + free(osp); | |
1956 | 1960 | free(ubbest); |
1957 | 1961 | return 0; |
1958 | 1962 | } |
... | ... | @@ -2052,6 +2056,9 @@ |
2052 | 2056 | |
2053 | 2057 | hdrsize = SA_HDR_SIZE(((sa_hdr_phys_t *) sahdrp)); |
2054 | 2058 | file->size = *(uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET); |
2059 | + if ((data->dnode.dn.dn_bonuslen == 0) && | |
2060 | + (data->dnode.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR)) | |
2061 | + free(sahdrp); | |
2055 | 2062 | } else { |
2056 | 2063 | file->size = zfs_to_cpu64(((znode_phys_t *) DN_BONUS(&data->dnode.dn))->zp_size, data->dnode.endian); |
2057 | 2064 | } |