From b3dff7182b4492456cb3124ebae67b65fefb5439 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sun, 8 Mar 2026 23:08:05 -0700 Subject: [PATCH] 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. --- lib/pinelog/pinelog.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pinelog/pinelog.c b/lib/pinelog/pinelog.c index 3d07133..8258044 100644 --- a/lib/pinelog/pinelog.c +++ b/lib/pinelog/pinelog.c @@ -118,7 +118,9 @@ int pinelog_init(int count) { num_modules = count; free(module_level); + module_level = NULL; free(module_name); + module_name = NULL; module_level = calloc(count, sizeof(*module_level)); if (module_level == NULL) { @@ -141,7 +143,9 @@ int pinelog_init(int count) { cleanup: num_modules = 0; free(module_level); + module_level = NULL; free(module_name); + module_name = NULL; return rc; } #if defined __has_attribute