mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-27 19:53:15 -04:00
selftests/lsm: Fix memory leak in attr_lsm_count
The calloc-allocated buffer in attr_lsm_count() is never released on
any exit path, including both the normal return path and the early
return when read_sysfs_lsms fails, resulting in a heap memory leak.
Add free() for the buffer on all return branches to fix the leak.
Fixes: d3d929a8b0 ("LSM: selftests for Linux Security Module syscalls")
Signed-off-by: Wang Yan <wangyan01@kylinos.cn>
Reviewed-by: William Roberts <bill.c.roberts@gmail.com>
Tested-by: William Roberts <bill.c.roberts@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
This commit is contained in:
@@ -76,7 +76,7 @@ int attr_lsm_count(void)
|
||||
return 0;
|
||||
|
||||
if (read_sysfs_lsms(names, sysconf(_SC_PAGESIZE)))
|
||||
return 0;
|
||||
goto out;
|
||||
|
||||
if (strstr(names, "selinux"))
|
||||
count++;
|
||||
@@ -85,5 +85,7 @@ int attr_lsm_count(void)
|
||||
if (strstr(names, "apparmor"))
|
||||
count++;
|
||||
|
||||
out:
|
||||
free(names);
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user