main-utils: don't leak description for command line arguments in nm_main_utils_early_setup()

(cherry picked from commit b5ca5bd7b7)
This commit is contained in:
Thomas Haller 2015-03-19 16:28:59 +01:00
parent 126723f94d
commit 9cc54f43bc

View file

@ -226,6 +226,8 @@ nm_main_utils_early_setup (const char *progname,
GError *error = NULL;
gboolean success = FALSE;
int i;
const char *opt_fmt_log_level = NULL, *opt_fmt_log_domains = NULL;
const char **opt_loc_log_level = NULL, **opt_loc_log_domains = NULL;
/* Make GIO ignore the remote VFS service; otherwise it tries to use the
* session bus to contact the remote service, and NM shouldn't ever be
@ -250,10 +252,15 @@ nm_main_utils_early_setup (const char *progname,
}
for (i = 0; options[i].long_name; i++) {
if (!strcmp (options[i].long_name, "log-level"))
if (!strcmp (options[i].long_name, "log-level")) {
opt_fmt_log_level = options[i].description;
opt_loc_log_level = &options[i].description;
options[i].description = g_strdup_printf (options[i].description, nm_logging_all_levels_to_string ());
else if (!strcmp (options[i].long_name, "log-domains"))
} else if (!strcmp (options[i].long_name, "log-domains")) {
opt_fmt_log_domains = options[i].description;
opt_loc_log_domains = &options[i].description;
options[i].description = g_strdup_printf (options[i].description, nm_logging_all_domains_to_string ());
}
}
/* Parse options */
@ -274,6 +281,15 @@ nm_main_utils_early_setup (const char *progname,
}
g_option_context_free (opt_ctx);
if (opt_loc_log_level) {
g_free ((char *) *opt_loc_log_level);
*opt_loc_log_level = opt_fmt_log_level;
}
if (opt_loc_log_domains) {
g_free ((char *) *opt_loc_log_domains);
*opt_loc_log_domains = opt_fmt_log_domains;
}
return success;
}