[PATCH] NAND: Free asprintf()-allocated space upon mtd device deletion.

Robert P. J. Day rpjday at crashcourse.ca
Mon Dec 21 04:43:50 EST 2009


Given that add_mtd_device() invokes asprintf() thusly:

  mtd->cdev.name = asprintf("nand%d", mtd->class_dev.id);
  ...
  mtd->param_size.value = asprintf("%u", mtd->size);
  ...
  mtd->cdev_oob.name = asprintf("nand_oob%d", mtd->class_dev.id);

make sure del_mtd_device() frees that in the reverse order.

Signed-off-by: Robert P. J. Day <rpjday at crashcourse.ca>

---

diff --git a/drivers/nand/nand.c b/drivers/nand/nand.c
index 0a6128c..bcf52bd 100644
--- a/drivers/nand/nand.c
+++ b/drivers/nand/nand.c
@@ -240,7 +240,9 @@ int add_mtd_device(struct mtd_info *mtd)
 int del_mtd_device (struct mtd_info *mtd)
 {
 	unregister_device(&mtd->class_dev);
+	free(mtd->cdev_oob.name);
 	free(mtd->param_size.value);
+	free(mtd->cdev.name);
 	return 0;
 }


========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
========================================================================



More information about the barebox mailing list