@@ -139,7 +139,8 @@ main(int argc, char *argv[])
nbctl_cmd_init();
/* Check if options are set via env var. */
- argv = ovs_cmdl_env_parse_all(&argc, argv, getenv("OVN_NBCTL_OPTIONS"));
+ char **argv_ = ovs_cmdl_env_parse_all(&argc, argv,
+ getenv("OVN_NBCTL_OPTIONS"));
/* ovn-nbctl has three operation modes:
*
@@ -157,7 +158,7 @@ main(int argc, char *argv[])
*/
struct ovs_cmdl_parsed_option *parsed_options;
size_t n_parsed_options;
- char *error_s = ovs_cmdl_parse_all(argc, argv, get_all_options(),
+ char *error_s = ovs_cmdl_parse_all(argc, argv_, get_all_options(),
&parsed_options, &n_parsed_options);
if (error_s) {
ctl_fatal("%s", error_s);
@@ -175,7 +176,7 @@ main(int argc, char *argv[])
|| has_option(parsed_options, n_parsed_options, 'u'))
&& !will_detach(parsed_options, n_parsed_options)) {
nbctl_client(socket_name, parsed_options, n_parsed_options,
- argc, argv);
+ argc, argv_);
}
/* Parse command line. */
@@ -199,19 +200,19 @@ main(int argc, char *argv[])
ovsdb_idl_set_leader_only(idl, leader_only);
if (daemon_mode) {
- server_loop(idl, argc, argv);
+ server_loop(idl, argc, argv_);
} else {
struct ctl_command *commands;
size_t n_commands;
char *error;
- error = ctl_parse_commands(argc - optind, argv + optind,
+ error = ctl_parse_commands(argc - optind, argv_ + optind,
&local_options, &commands, &n_commands);
if (error) {
ctl_fatal("%s", error);
}
- char *args = process_escape_args(argv);
+ char *args = process_escape_args(argv_);
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);
@@ -243,6 +244,10 @@ cleanup:
ovsdb_idl_destroy(idl);
idl = the_idl = NULL;
+ for (int i = 0; i < argc; i++) {
+ free(argv_[i]);
+ }
+ free(argv_);
exit(EXIT_SUCCESS);
}
@@ -109,13 +109,14 @@ main(int argc, char *argv[])
sbctl_cmd_init();
/* Check if options are set via env var. */
- argv = ovs_cmdl_env_parse_all(&argc, argv, getenv("OVN_SBCTL_OPTIONS"));
+ char **argv_ = ovs_cmdl_env_parse_all(&argc, argv,
+ getenv("OVN_SBCTL_OPTIONS"));
/* Parse command line. */
- char *args = process_escape_args(argv);
+ char *args = process_escape_args(argv_);
shash_init(&local_options);
- parse_options(argc, argv, &local_options);
- char *error = ctl_parse_commands(argc - optind, argv + optind,
+ parse_options(argc, argv_, &local_options);
+ char *error = ctl_parse_commands(argc - optind, argv_ + optind,
&local_options, &commands, &n_commands);
if (error) {
ctl_fatal("%s", error);
@@ -149,8 +150,7 @@ main(int argc, char *argv[])
if (seqno != ovsdb_idl_get_seqno(idl)) {
seqno = ovsdb_idl_get_seqno(idl);
if (do_sbctl(args, commands, n_commands, idl)) {
- free(args);
- exit(EXIT_SUCCESS);
+ break;
}
}
@@ -159,6 +159,13 @@ main(int argc, char *argv[])
poll_block();
}
}
+
+ for (int i = 0; i < argc; i++) {
+ free(argv_[i]);
+ }
+ free(argv_);
+ free(args);
+ exit(EXIT_SUCCESS);
}
static void
This is not a real leak but it's reported by valgrind as such and creates noise in the output. Signed-off-by: Dumitru Ceara <dceara@redhat.com> --- utilities/ovn-nbctl.c | 17 +++++++++++------ utilities/ovn-sbctl.c | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-)