Skip to content

Commit

Permalink
test_firmware: fix a memory leak bug
Browse files Browse the repository at this point in the history
[ Upstream commit d4fddac ]

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]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
wenwenwang1 authored and gregkh committed Aug 16, 2019
1 parent 7faeeb9 commit 8d4611f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/test_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,11 @@ static int __init test_firmware_init(void)
return -ENOMEM;

rc = __test_firmware_config_init();
if (rc)
if (rc) {
kfree(test_fw_config);
pr_err("could not init firmware test config: %d\n", rc);
return rc;
}

rc = misc_register(&test_fw_misc_device);
if (rc) {
Expand Down

0 comments on commit 8d4611f

Please sign in to comment.