From 6c567bdc2b84b0a680ff66d2e2e9818a8517e8d0 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 29 Oct 2024 14:52:30 -0400 Subject: [PATCH] MT#61352 fix mem leak in config_load_ext g_option_context_parse() modifies the argv given to it, so g_strfreev() called during the cleanup cannot free all the strings that have been duplicated by g_strdupv(). Make a second, shallow copy of the array, and use that to free all the strings that were duplicated. Change-Id: Ifcb31cb5e6141a1e15de47e11ab800c9d3e0ab10 (cherry picked from commit 86da10f6a7164e1c95aad9cb590772a8ba9669ef) (cherry picked from commit 6b962a39e0c89472f77975751cc5caa1c6fd54c1) --- lib/auxlib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/auxlib.c b/lib/auxlib.c index 3c2c8c72a..d376b3f4f 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -153,6 +153,8 @@ void config_load_free(struct rtpengine_common_config *cconfig) { } G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionEntry, free) +typedef char *char_p_shallow; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(char_p_shallow, g_free) void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char *description, char *default_config, char *default_section, @@ -163,7 +165,8 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char g_autoptr(char) use_section = NULL; const char *use_config; int fatal = 0; - g_autoptr(char_p) saved_argv = g_strdupv(*argv); + g_autoptr(char_p) saved_argv_arr = g_strdupv(*argv); + g_autoptr(char_p_shallow) saved_argv = __g_memdup(saved_argv_arr, sizeof(char *) * (*argc + 1)); int saved_argc = *argc; gboolean version = false;