firmware: Fix memory leak in error path
Subsystems (2)
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
@@ -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
Quoted 13 lines · Firo Yang
In error path, we forgot to free
fw_workalloced by kzalloc. This will make a memory leak. So just free it before return.Signed-off-by Firo Yang <[email protected]>--- drivers/base/firmware_class.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/base/firmware_class.c +0
-0
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
-1fw_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
Quoted 16 lines · Julia Lawall
Quoted 14 lines · Firo Yang
In error path, we forgot to free
fw_workalloced by kzalloc. This will make a memory leak. So just free it before return.Signed-off-by Firo Yang <[email protected]>--- drivers/base/firmware_class.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/base/firmware_class.c +0
-0@@ -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
-1fw_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
-1fw_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