Commit 2d320b10 authored by Ilpo Järvinen's avatar Ilpo Järvinen Committed by Shuah Khan

selftests/resctrl: Don't leak buffer in fill_cache()

The error path in fill_cache() does return before the allocated buffer
is freed leaking the buffer.

The leak was introduced when fill_cache_read() started to return errors
in commit c7b607fa ("selftests/resctrl: Fix null pointer
dereference on open failed"), before that both fill functions always
returned 0.

Move free() earlier to prevent the mem leak.

Fixes: c7b607fa ("selftests/resctrl: Fix null pointer dereference on open failed")
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Tested-by: default avatarBabu Moger <babu.moger@amd.com>
Tested-by: default avatarShaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 8e289f45
...@@ -177,12 +177,13 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, ...@@ -177,12 +177,13 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush,
else else
ret = fill_cache_write(start_ptr, end_ptr, resctrl_val); ret = fill_cache_write(start_ptr, end_ptr, resctrl_val);
free(startptr);
if (ret) { if (ret) {
printf("\n Error in fill cache read/write...\n"); printf("\n Error in fill cache read/write...\n");
return -1; return -1;
} }
free(startptr);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment