Skip to contentSkip to conversation

ubifs: fix memory leak on error condition

PATCH Superseded Garry McNulty 3 participants 3 messages Nov 15, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubifs: fix memory leak on error condition

If the call to ubifs_read_nnode() fails in ubifs_lpt_calc_hash() an error is returned without freeing the memory allocated to 'buf'. Jump to 'out' label to free allocated memory and return the error code.

Detected by CoverityScan, CID 1441025 ("Resource leak")

---
 fs/ubifs/lpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/lpt.c +1 -1
index d1d5e96350dd..c162459a1e02 100644
@@ -1688,7 +1688,7 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash)
 	if (!c->nroot) {
 		err = ubifs_read_nnode(c, NULL, 0);
 		if (err)
-			return err;
+			goto out;
 	}
 
 	cnode = (struct ubifs_cnode *)c->nroot;
Signature · 1 line
2.14.5
#1 lore raw

Am Donnerstag, 15. November 2018, 21:38:50 CET schrieb Garry McNulty:

Quoted 16 lines

If the call to ubifs_read_nnode() fails in ubifs_lpt_calc_hash() an error is returned without freeing the memory allocated to 'buf'. Jump to 'out' label to free allocated memory and return the error code.

Detected by CoverityScan, CID 1441025 ("Resource leak")

---
 fs/ubifs/lpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/lpt.c +0 -0
index d1d5e96350dd..c162459a1e02 100644

fs/ubifs/lpt.c int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash) · line 1694

Quoted 8 lines
fs/ubifs/lpt.c +1 -1
@@ -1688,7 +1688,7 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash)
 	if (!c->nroot) {
 		err = ubifs_read_nnode(c, NULL, 0);
 		if (err)
-			return err;
+			goto out;
 	}
 
 	cnode = (struct ubifs_cnode *)c->nroot;

Please see:
http://lists.infradead.org/pipermail/linux-mtd/2018-October/085081.html

If Colin won't send a v2, please do you so, then I'll take your v2.

Thanks,
//richard

#2 lore raw
Quoted 24 lines · Richard Weinberger

Am Donnerstag, 15. November 2018, 21:38:50 CET schrieb Garry McNulty:

Quoted 23 lines

If the call to ubifs_read_nnode() fails in ubifs_lpt_calc_hash() an error is returned without freeing the memory allocated to 'buf'. Jump to 'out' label to free allocated memory and return the error code.

Detected by CoverityScan, CID 1441025 ("Resource leak")

---
 fs/ubifs/lpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/lpt.c +1 -1
index d1d5e96350dd..c162459a1e02 100644
@@ -1688,7 +1688,7 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash)
 	if (!c->nroot) {
 		err = ubifs_read_nnode(c, NULL, 0);
 		if (err)
-			return err;
+			goto out;
 	}
 
Quoted 6 lines

fs/ubifs/lpt.c int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash) · line 1694

Quoted 1 line
fs/ubifs/lpt.c +0 -0
 	cnode = (struct ubifs_cnode *)c->nroot;

Please see:
http://lists.infradead.org/pipermail/linux-mtd/2018-October/085081.html

If Colin won't send a v2, please do you so, then I'll take your v2.

Please take Garry's V2, sorry, I somehow overlooked doing a V2.

Quoted 5 lines

Thanks,
//richard