[ovs-dev] [PATCH 3/5] ovs-vsctl, vtep-ctl: Free 'args' string on exit.
William Tu
u9012063 at gmail.com
Fri Jan 26 15:45:26 UTC 2018
On Thu, Jan 25, 2018 at 3:39 PM, Ben Pfaff <blp at ovn.org> wrote:
> This avoids a memory leak warning from valgrind.
>
> ovn-sbctl and ovn-nbctl already followed this pattern.
>
> Signed-off-by: Ben Pfaff <blp at ovn.org>
> ---
Looks good to me.
Acked-by: William Tu <u9012063 at gmail.com>
> utilities/ovs-vsctl.c | 12 ++++++++----
> vtep/vtep-ctl.c | 12 ++++++++----
> 2 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
> index 7b909431db32..6e47ca361ac4 100644
> --- a/utilities/ovs-vsctl.c
> +++ b/utilities/ovs-vsctl.c
> @@ -97,7 +97,7 @@ OVS_NO_RETURN static void usage(void);
> static void parse_options(int argc, char *argv[], struct shash *local_options);
> static void run_prerequisites(struct ctl_command[], size_t n_commands,
> struct ovsdb_idl *);
> -static void do_vsctl(const char *args, struct ctl_command *, size_t n,
> +static bool do_vsctl(const char *args, struct ctl_command *, size_t n,
> struct ovsdb_idl *);
>
> /* post_db_reload_check frame work is to allow ovs-vsctl to do additional
> @@ -181,7 +181,10 @@ main(int argc, char *argv[])
>
> if (seqno != ovsdb_idl_get_seqno(idl)) {
> seqno = ovsdb_idl_get_seqno(idl);
> - do_vsctl(args, commands, n_commands, idl);
> + if (do_vsctl(args, commands, n_commands, idl)) {
> + free(args);
> + exit(EXIT_SUCCESS);
> + }
> }
>
> if (seqno == ovsdb_idl_get_seqno(idl)) {
> @@ -2482,7 +2485,7 @@ vsctl_parent_process_info(void)
> #endif
> }
>
> -static void
> +static bool
> do_vsctl(const char *args, struct ctl_command *commands, size_t n_commands,
> struct ovsdb_idl *idl)
> {
> @@ -2666,7 +2669,7 @@ do_vsctl(const char *args, struct ctl_command *commands, size_t n_commands,
> ovsdb_idl_txn_destroy(txn);
> ovsdb_idl_destroy(idl);
>
> - exit(EXIT_SUCCESS);
> + return true;
>
> try_again:
> /* Our transaction needs to be rerun, or a prerequisite was not met. Free
> @@ -2682,6 +2685,7 @@ try_again:
> free(c->table);
> }
> free(error);
> + return false;
> }
>
> /* Frees the current transaction and the underlying IDL and then calls
> diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c
> index 3af71498bc02..056dc687aa16 100644
> --- a/vtep/vtep-ctl.c
> +++ b/vtep/vtep-ctl.c
> @@ -82,7 +82,7 @@ OVS_NO_RETURN static void usage(void);
> static void parse_options(int argc, char *argv[], struct shash *local_options);
> static void run_prerequisites(struct ctl_command[], size_t n_commands,
> struct ovsdb_idl *);
> -static void do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
> +static bool do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
> struct ovsdb_idl *);
> static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
> const char *name,
> @@ -144,7 +144,10 @@ main(int argc, char *argv[])
>
> if (seqno != ovsdb_idl_get_seqno(idl)) {
> seqno = ovsdb_idl_get_seqno(idl);
> - do_vtep_ctl(args, commands, n_commands, idl);
> + if (do_vtep_ctl(args, commands, n_commands, idl)) {
> + free(args);
> + exit(EXIT_SUCCESS);
> + }
> }
>
> if (seqno == ovsdb_idl_get_seqno(idl)) {
> @@ -2257,7 +2260,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands,
> }
> }
>
> -static void
> +static bool
> do_vtep_ctl(const char *args, struct ctl_command *commands,
> size_t n_commands, struct ovsdb_idl *idl)
> {
> @@ -2405,7 +2408,7 @@ do_vtep_ctl(const char *args, struct ctl_command *commands,
>
> ovsdb_idl_destroy(idl);
>
> - exit(EXIT_SUCCESS);
> + return true;
>
> try_again:
> /* Our transaction needs to be rerun, or a prerequisite was not met. Free
> @@ -2421,6 +2424,7 @@ try_again:
> free(c->table);
> }
> free(error);
> + return false;
> }
>
> static const struct ctl_command_syntax vtep_commands[] = {
> --
> 2.10.2
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
More information about the dev
mailing list