[PATCH] Staging: comedi: fix memory leak in comedi_bond.c

Chase Southwood chase.southwood at yahoo.com
Sat Feb 8 05:02:27 UTC 2014


We allocate bdev and then krealloc the devs pointer in order to add bdev
at the end of the devpriv->devs array list.  But if for some reason this
krealloc fails, we need to free bdev before returning an error otherwise
this memory is leaked.

Signed-off-by: Chase Southwood <chase.southwood at yahoo.com>
---
 drivers/staging/comedi/drivers/comedi_bond.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index 51a59e5..406aedb 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -254,6 +254,7 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
 			if (!devs) {
 				dev_err(dev->class_dev,
 					"Could not allocate memory. Out of memory?\n");
+				kfree(bdev);
 				return -ENOMEM;
 			}
 			devpriv->devs = devs;
-- 
1.8.5.3



More information about the devel mailing list