ebb439
From 87e4b1c8533f5b42175366706daff9c706dd1ecf Mon Sep 17 00:00:00 2001
ebb439
From: Ilya Maximets <i.maximets@ovn.org>
ebb439
Date: Fri, 20 Nov 2020 01:17:16 +0100
ebb439
Subject: [PATCH 08/16] pinctrl: Fix leak of DNS cache records.
ebb439
ebb439
'smap_clear()' doesn't free allocated memory, but 'smap_clone()'
ebb439
re-initializes hash map clearing internal pointers and leaking
ebb439
this memory.  'smap_destroy()' should be used instead.
ebb439
ebb439
Also, all the records and array of datapaths should be freed on
ebb439
destruction of a cache entry.
ebb439
ebb439
  Direct leak of 16 byte(s) in 2 object(s) allocated from:
ebb439
    #0 0x5211c7 in calloc (/controller/ovn-controller+0x5211c7)
ebb439
    #1 0x752364 in xcalloc /lib/util.c:121:31
ebb439
    #2 0x576e76 in sync_dns_cache /controller/pinctrl.c:2517:25
ebb439
    #3 0x5758fb in pinctrl_run /controller/pinctrl.c:3158:5
ebb439
    #4 0x59b06c in main /controller/ovn-controller.c:2642:25
ebb439
    #5 0x7fb570fc11a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
ebb439
ebb439
  Indirect leak of 26 byte(s) in 2 object(s) allocated from:
ebb439
    #0 0x52100f in malloc (/controller/ovn-controller+0x52100f)
ebb439
    #1 0x7523d6 in xmalloc /lib/util.c:138:15
ebb439
    #2 0x7524a8 in xmemdup0 /lib/util.c:168:15
ebb439
    #3 0x73d8fc in smap_clone /lib/smap.c:314:45
ebb439
    #4 0x576e2f in sync_dns_cache /controller/pinctrl.c:2513:13
ebb439
    #5 0x5758fb in pinctrl_run /controller/pinctrl.c:3158:5
ebb439
    #6 0x59b06c in main /controller/ovn-controller.c:2642:25
ebb439
    #7 0x7fb570fc11a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
ebb439
ebb439
Fixes: 6b72068202f1 ("ovn-controller: Add a new thread in pinctrl module to handle packet-ins.")
ebb439
Acked-by: Dumitru Ceara <dceara@redhat.com>
ebb439
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
ebb439
Signed-off-by: Numan Siddique <numans@ovn.org>
ebb439
---
ebb439
 controller/pinctrl.c | 6 +++++-
ebb439
 1 file changed, 5 insertions(+), 1 deletion(-)
ebb439
ebb439
diff --git a/controller/pinctrl.c b/controller/pinctrl.c
ebb439
index 728fb3063..d445d235e 100644
ebb439
--- a/controller/pinctrl.c
ebb439
+++ b/controller/pinctrl.c
ebb439
@@ -2508,7 +2508,7 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table)
ebb439
         dns_data->delete = false;
ebb439
 
ebb439
         if (!smap_equal(&dns_data->records, &sbrec_dns->records)) {
ebb439
-            smap_clear(&dns_data->records);
ebb439
+            smap_destroy(&dns_data->records);
ebb439
             smap_clone(&dns_data->records, &sbrec_dns->records);
ebb439
         }
ebb439
 
ebb439
@@ -2524,6 +2524,8 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table)
ebb439
         struct dns_data *d = iter->data;
ebb439
         if (d->delete) {
ebb439
             shash_delete(&dns_cache, iter);
ebb439
+            smap_destroy(&d->records);
ebb439
+            free(d->dps);
ebb439
             free(d);
ebb439
         }
ebb439
     }
ebb439
@@ -2536,6 +2538,8 @@ destroy_dns_cache(void)
ebb439
     SHASH_FOR_EACH_SAFE (iter, next, &dns_cache) {
ebb439
         struct dns_data *d = iter->data;
ebb439
         shash_delete(&dns_cache, iter);
ebb439
+        smap_destroy(&d->records);
ebb439
+        free(d->dps);
ebb439
         free(d);
ebb439
     }
ebb439
 }
ebb439
-- 
ebb439
2.28.0
ebb439