Skip to contentSkip to conversation

firmware: Fix memory leak in error path

PATCH Superseded Firo Yang 2 participants 3 messages Jun 5, 2015 – Jun 6, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Firo Yang

author
#0 lore raw

PATCH 1/1 firmware: Fix memory leak in error path

In error path, we forgot to free fw_work alloced by kzalloc. This will make a memory leak. So just free it before return.

---
 drivers/base/firmware_class.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/firmware_class.c +3 -1
index 8c3aa3c..9c42883 100644
@@ -1307,8 +1307,10 @@ request_firmware_nowait(
 
 	fw_work->module = module;
 	fw_work->name = kstrdup_const(name, gfp);
-	if (!fw_work->name)
+	if (!fw_work->name) {
+		kfree(fw_work);
 		return -ENOMEM;
+	}
 	fw_work->device = device;
 	fw_work->context = context;
 	fw_work->cont = cont;
Signature · 1 line
2.4.2
#1 lore raw
Quoted 13 lines · Firo Yang

In error path, we forgot to free fw_work alloced by kzalloc. This will make a memory leak. So just free it before return.

---
 drivers/base/firmware_class.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/firmware_class.c +0 -0
index 8c3aa3c..9c42883 100644

drivers/base/firmware_class.c request_firmware_nowait( · line 1313

Quoted 8 lines
drivers/base/firmware_class.c +3 -1
@@ -1307,8 +1307,10 @@ request_firmware_nowait(
 
 	fw_work->module = module;
 	fw_work->name = kstrdup_const(name, gfp);
-	if (!fw_work->name)
+	if (!fw_work->name) {
+		kfree(fw_work);
 		return -ENOMEM;
+	}

Maybe it would be better to unify the error handling code at the end of the function, if things are being forgotten.

julia

Quoted 11 lines
drivers/base/firmware_class.c +0 -1
 	fw_work->device = device;
 	fw_work->context = context;
 	fw_work->cont = cont;
--

2.4.2

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#2 lore raw
In reply to Firo Yang
Quoted 16 lines · Julia Lawall
Quoted 14 lines · Firo Yang

In error path, we forgot to free fw_work alloced by kzalloc. This will make a memory leak. So just free it before return.

---
 drivers/base/firmware_class.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/firmware_class.c +0 -0
index 8c3aa3c..9c42883 100644
@@ -1307,8 +1307,10 @@ request_firmware_nowait(
 
Quoted 10 lines

drivers/base/firmware_class.c request_firmware_nowait( · line 1313

Quoted 7 lines
drivers/base/firmware_class.c +3 -1
 	fw_work->module = module;
 	fw_work->name = kstrdup_const(name, gfp);
-	if (!fw_work->name)
+	if (!fw_work->name) {
+		kfree(fw_work);
 		return -ENOMEM;
+	}

Maybe it would be better to unify the error handling code at the end of the function, if things are being forgotten.

Thanks Julia!
I will reconstruct the code.

Firo

Quoted 14 lines

julia

Quoted 11 lines
drivers/base/firmware_class.c +0 -1
 	fw_work->device = device;
 	fw_work->context = context;
 	fw_work->cont = cont;
--

2.4.2

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html