From 91e4f4dcbd941ff03aedafe46300b5f4eb40ec23 Mon Sep 17 00:00:00 2001 From: Yi-Hung Wei Date: Fri, 7 Apr 2017 14:43:45 -0700 Subject: [PATCH] ovn-nbctl: Fix memory leak in nbctl_lr_nat_list() In testcase "2319: ovn-nbctl - NATs", valgrind reports a memory leak with the following code stack. xmalloc (util.c:112) xvasprintf (util.c:176) xasprintf (util.c:272) nbctl_lr_nat_list (ovn-nbctl.c:2400) do_nbctl (ovn-nbctl.c:3121) main (ovn-nbctl.c:142) Signed-off-by: Yi-Hung Wei Signed-off-by: Ben Pfaff --- ovn/utilities/ovn-nbctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index e9dcde701..e5999a654 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -2411,7 +2411,7 @@ nbctl_lr_nat_list(struct ctl_context *ctx) struct smap lr_nats = SMAP_INITIALIZER(&lr_nats); for (size_t i = 0; i < lr->n_nat; i++) { const struct nbrec_nat *nat = lr->nat[i]; - const char *key = xasprintf("%-17.13s%s", nat->type, nat->external_ip); + char *key = xasprintf("%-17.13s%s", nat->type, nat->external_ip); if (nat->external_mac && nat->logical_port) { smap_add_format(&lr_nats, key, "%-22.18s%-21.17s%s", nat->logical_ip, nat->external_mac, @@ -2419,6 +2419,7 @@ nbctl_lr_nat_list(struct ctl_context *ctx) } else { smap_add_format(&lr_nats, key, "%s", nat->logical_ip); } + free(key); } const struct smap_node **nodes = smap_sort(&lr_nats); -- 2.39.5