Skip to contentSkip to conversation

: (error) Uninitialized variable: ct

U-Boot New Wolfgang Denk 3 participants 3 messages Nov 6, 2014 – Nov 10, 2014

lore
Share & tools
lore
#0 lore raw

Hello,

cppcheck reports:

[fs/zfs/zfs.c:743]: (error) Uninitialized variable: ct [fs/zfs/zfs.c:937]: (error) Memory leak: l [fs/zfs/zfs.c:1048]: (error) Memory leak: zapbuf [fs/zfs/zfs.c:1083]: (error) Memory leak: zapbuf [fs/zfs/zfs.c:1141]: (error) Memory leak: dnbuf [fs/zfs/zfs.c:1372]: (error) Memory leak: osp [fs/zfs/zfs.c:1726]: (error) Memory leak: nvlist [fs/zfs/zfs.c:1869]: (error) Memory leak: ub_array [fs/zfs/zfs.c:1957]: (error) Memory leak: osp [fs/zfs/zfs.c:2047]: (error) Memory leak: sahdrp

can you please have a look? Thanks!

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Those who do not  understand  Unix  are  condemned  to  reinvent  it,
poorly.              - Henry Spencer, University of Toronto Unix hack
#1 lore raw

PATCH 1/1 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:

Quoted 1 line

[fs/zfs/zfs.c:937]: (error) Memory leak: l

dmu_read() allocates "l" if successful, so error-case should not free it.

Quoted 1 line

[fs/zfs/zfs.c:1141]: (error) Memory leak: dnbuf

dmu_read() allocates "dnbuf" if successful, so error-case should not free it.

Quoted 1 line

[fs/zfs/zfs.c:1372]: (error) Memory leak: osp

zio_read() allocates "osp" if successful, so error-case should not free it.

Quoted 1 line

[fs/zfs/zfs.c:1726]: (error) Memory leak: nvlist

int_zfs_fetch_nvlist() allocates "nvlist" if successful, so error-case should not free it.

---
 fs/zfs/zfs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/zfs/zfs.c +8 -1
index 818d3d9..fb2b3ee 100644
@@ -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);
 	}
Signature · 1 line
2.0.0
#2 lore raw

PATCH 1/1 ZFS: Clean up cppcheck warnings where relevant, leaked memory etc

Quoted 10 lines · Jorgen Lundman

In a message from Wolfgang Denk highlighting warnings from cppcheck, the patch will address those that are correctly diagnosed. Some are false-positives:

Quoted 1 line

[fs/zfs/zfs.c:937]: (error) Memory leak: l

dmu_read() allocates "l" if successful, so error-case should not free it.

Quoted 1 line

[fs/zfs/zfs.c:1141]: (error) Memory leak: dnbuf

dmu_read() allocates "dnbuf" if successful, so error-case should not free it.

Quoted 8 lines
Quoted 1 line

[fs/zfs/zfs.c:1372]: (error) Memory leak: osp

zio_read() allocates "osp" if successful, so error-case should not free it.

Quoted 1 line

[fs/zfs/zfs.c:1726]: (error) Memory leak: nvlist

int_zfs_fetch_nvlist() allocates "nvlist" if successful, so error-case should not free it.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141110/c0e64719/attachment.pgp>