linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [2.6 patch] mtd/ubi/vtbl.c: fix memory leak
@ 2008-03-03 18:07 Adrian Bunk
  2008-03-04  6:27 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Bunk @ 2008-03-03 18:07 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: linux-mtd, linux-kernel

This patch fixes a memory leak introduced by commit 
4ccf8cffa963c7b5bdc6d455ea9417084ee49aa8 and spotted by the Coverity 
checker.

Signed-off-by: Adrian Bunk <bunk@kernel.org>

---

 drivers/mtd/ubi/vtbl.c |    1 +
 1 file changed, 1 insertion(+)

--- linux-2.6/drivers/mtd/ubi/vtbl.c.orig	2008-03-02 14:06:25.000000000 +0200
+++ linux-2.6/drivers/mtd/ubi/vtbl.c	2008-03-02 14:15:54.000000000 +0200
@@ -502,40 +502,41 @@ static int init_volumes(struct ubi_devic
 		vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
 		if (!vol)
 			return -ENOMEM;
 
 		vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
 		vol->alignment = be32_to_cpu(vtbl[i].alignment);
 		vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
 		vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
 					UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
 		vol->name_len = be16_to_cpu(vtbl[i].name_len);
 		vol->usable_leb_size = ubi->leb_size - vol->data_pad;
 		memcpy(vol->name, vtbl[i].name, vol->name_len);
 		vol->name[vol->name_len] = '\0';
 		vol->vol_id = i;
 
 		if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) {
 			/* Auto re-size flag may be set only for one volume */
 			if (ubi->autoresize_vol_id != -1) {
 				ubi_err("more then one auto-resize volume (%d "
 					"and %d)", ubi->autoresize_vol_id, i);
+				kfree(vol);
 				return -EINVAL;
 			}
 
 			ubi->autoresize_vol_id = i;
 		}
 
 		ubi_assert(!ubi->volumes[i]);
 		ubi->volumes[i] = vol;
 		ubi->vol_count += 1;
 		vol->ubi = ubi;
 		reserved_pebs += vol->reserved_pebs;
 
 		/*
 		 * In case of dynamic volume UBI knows nothing about how many
 		 * data is stored there. So assume the whole volume is used.
 		 */
 		if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
 			vol->used_ebs = vol->reserved_pebs;
 			vol->last_eb_bytes = vol->usable_leb_size;
 			vol->used_bytes =


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [2.6 patch] mtd/ubi/vtbl.c: fix memory leak
  2008-03-03 18:07 [2.6 patch] mtd/ubi/vtbl.c: fix memory leak Adrian Bunk
@ 2008-03-04  6:27 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2008-03-04  6:27 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: Artem Bityutskiy, linux-mtd, linux-kernel

On Mon, 2008-03-03 at 20:07 +0200, Adrian Bunk wrote:
> This patch fixes a memory leak introduced by commit 
> 4ccf8cffa963c7b5bdc6d455ea9417084ee49aa8 and spotted by the Coverity 
> checker.
> 
> Signed-off-by: Adrian Bunk <bunk@kernel.org>

Good catch, thank you!

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-03-04  6:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-03 18:07 [2.6 patch] mtd/ubi/vtbl.c: fix memory leak Adrian Bunk
2008-03-04  6:27 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).