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
pull/1876/head
Richard Fuchs 1 year ago
parent 9f019fd7fe
commit 86da10f6a7

@ -156,6 +156,8 @@ void config_load_free(struct rtpengine_common_config *cconfig) {
} }
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionEntry, free) 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, void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char *description,
char *default_config, char *default_section, char *default_config, char *default_section,
@ -166,7 +168,8 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
g_autoptr(char) use_section = NULL; g_autoptr(char) use_section = NULL;
const char *use_config; const char *use_config;
int fatal = 0; 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; int saved_argc = *argc;
gboolean version = false; gboolean version = false;
g_autoptr(char) opus_application = NULL; g_autoptr(char) opus_application = NULL;

Loading…
Cancel
Save