Skip to content

Commit d4fddac

Browse files
wenwenwang1gregkh
authored andcommitted
test_firmware: fix a memory leak bug
In test_firmware_init(), the buffer pointed to by the global pointer 'test_fw_config' is allocated through kzalloc(). Then, the buffer is initialized in __test_firmware_config_init(). In the case that the initialization fails, the following execution in test_firmware_init() needs to be terminated with an error code returned to indicate this failure. However, the allocated buffer is not freed on this execution path, leading to a memory leak bug. To fix the above issue, free the allocated buffer before returning from test_firmware_init(). Signed-off-by: Wenwen Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0c7d37f commit d4fddac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/test_firmware.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,11 @@ static int __init test_firmware_init(void)
886886
return -ENOMEM;
887887

888888
rc = __test_firmware_config_init();
889-
if (rc)
889+
if (rc) {
890+
kfree(test_fw_config);
891+
pr_err("could not init firmware test config: %d\n", rc);
890892
return rc;
893+
}
891894

892895
rc = misc_register(&test_fw_misc_device);
893896
if (rc) {

0 commit comments

Comments
 (0)