[ovs-dev] [PATCH ovn] ovn-northd: Fix leak of the ipv6_prefix_set array.

Ilya Maximets i.maximets at ovn.org
Wed May 13 12:56:03 UTC 2020


'sset_array' allocates new array that must be freed by the caller:

 640 bytes in 40 blocks are definitely lost in loss record 73 of 74
    at 0x483980B: malloc (vg_replace_malloc.c:309)
    by 0x4B4B94: xmalloc (util.c:138)
    by 0x4AEA03: sset_array (sset.c:344)
    by 0x424210: ovn_update_ipv6_prefix (ovn-northd.c:2726)
    by 0x424210: ovnnb_db_run (ovn-northd.c:11148)
    by 0x424210: ovn_db_run (ovn-northd.c:11692)
    by 0x408C78: main (ovn-northd.c:12055)

'sset' used here to store only one string, so it's not really needed.
Removing the 'ipv6_prefix_set' to simplify the code and avoid memory
leak.  New variable introduced to avoid casting issues with sparse
and -Wcast-align.

Fixes: 5c1d2d230773 ("northd: Add logical flows for dhcpv6 pfd parsing")
Signed-off-by: Ilya Maximets <i.maximets at ovn.org>
---
 northd/ovn-northd.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index b25152d74..aebc72152 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -2721,12 +2721,8 @@ ovn_update_ipv6_prefix(struct hmap *ports)
             continue;
         }
 
-        struct sset ipv6_prefix_set = SSET_INITIALIZER(&ipv6_prefix_set);
-        sset_add(&ipv6_prefix_set, prefix);
-        nbrec_logical_router_port_set_ipv6_prefix(op->nbrp,
-                                            sset_array(&ipv6_prefix_set),
-                                            sset_count(&ipv6_prefix_set));
-        sset_destroy(&ipv6_prefix_set);
+        const char *prefix_ptr = prefix;
+        nbrec_logical_router_port_set_ipv6_prefix(op->nbrp, &prefix_ptr, 1);
     }
 }
 
-- 
2.25.4



More information about the dev mailing list