mirror of https://github.com/nirenjan/libx52.git
fix: Handle possible double-free in pinelog
The pinelog_init function frees the module_level and module_name pointers at the start of the function, but doesn't reset them back to NULL. If a subsequent malloc fails, then it would attempt to free the pointer again, resulting in a double-free situation. However, this is only hit if the pinelog_init function is called more than once. While this is not likely (given that I'm the only known user of pinelog at this time), it's still good coding practice.pull/60/head
parent
0356a2d610
commit
b3dff7182b
|
|
@ -118,7 +118,9 @@ int pinelog_init(int count) {
|
||||||
|
|
||||||
num_modules = count;
|
num_modules = count;
|
||||||
free(module_level);
|
free(module_level);
|
||||||
|
module_level = NULL;
|
||||||
free(module_name);
|
free(module_name);
|
||||||
|
module_name = NULL;
|
||||||
|
|
||||||
module_level = calloc(count, sizeof(*module_level));
|
module_level = calloc(count, sizeof(*module_level));
|
||||||
if (module_level == NULL) {
|
if (module_level == NULL) {
|
||||||
|
|
@ -141,7 +143,9 @@ int pinelog_init(int count) {
|
||||||
cleanup:
|
cleanup:
|
||||||
num_modules = 0;
|
num_modules = 0;
|
||||||
free(module_level);
|
free(module_level);
|
||||||
|
module_level = NULL;
|
||||||
free(module_name);
|
free(module_name);
|
||||||
|
module_name = NULL;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#if defined __has_attribute
|
#if defined __has_attribute
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue