Re: [PATCH 4/5] usb: gadget: f_mass_storage: Fix potential memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 05 Apr 2011 17:36:41 +0200, Roger Quadros <roger.quadros@xxxxxxxxx> wrote:

If allocation of multiple buffers would fail then we would leak memory.
Fix that.

Signed-off-by: Roger Quadros <roger.quadros@xxxxxxxxx>
---
 drivers/usb/gadget/f_mass_storage.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index f6bd001..60b4df9 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2863,6 +2863,12 @@ buffhds_first_it:
 		bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
 		if (unlikely(!bh->buf)) {
 			rc = -ENOMEM;
+			/* clean up */
+			while (i < FSG_NUM_BUFFERS) {
+				bh--;
+				kfree(bh->buf);
+				i++;
+			}
 			goto error_release;
 		}
 	} while (--i);

This is handled in fsg_common_release(), isn't it?  Feel free to
send a patch with a comment explaining that.

--
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michal "mina86" Nazarewicz    (o o)
ooo +-----<email/xmpp: mnazarewicz@xxxxxxxxxx>-----ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux