]> git.proxmox.com Git - ovs.git/commitdiff
ovn-nbctl: Fix memory leak in nbctl_lr_nat_list()
authorYi-Hung Wei <yihung.wei@gmail.com>
Fri, 7 Apr 2017 21:43:45 +0000 (14:43 -0700)
committerBen Pfaff <blp@ovn.org>
Mon, 24 Apr 2017 16:45:15 +0000 (09:45 -0700)
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 <yihung.wei@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
ovn/utilities/ovn-nbctl.c

index e9dcde7012e44fb3612d2fbc90354b81adafcf03..e5999a654131df1a2feacca11e419d4245596ed1 100644 (file)
@@ -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);