Skip to content

Commit

Permalink
pinctrl: Fix leak of DNS cache records.
Browse files Browse the repository at this point in the history
'smap_clear()' doesn't free allocated memory, but 'smap_clone()'
re-initializes hash map clearing internal pointers and leaking
this memory.  'smap_destroy()' should be used instead.

Also, all the records and array of datapaths should be freed on
destruction of a cache entry.

  Direct leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x5211c7 in calloc (/controller/ovn-controller+0x5211c7)
    #1 0x752364 in xcalloc /lib/util.c:121:31
    #2 0x576e76 in sync_dns_cache /controller/pinctrl.c:2517:25
    #3 0x5758fb in pinctrl_run /controller/pinctrl.c:3158:5
    #4 0x59b06c in main /controller/ovn-controller.c:2642:25
    #5 0x7fb570fc11a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)

  Indirect leak of 26 byte(s) in 2 object(s) allocated from:
    #0 0x52100f in malloc (/controller/ovn-controller+0x52100f)
    #1 0x7523d6 in xmalloc /lib/util.c:138:15
    #2 0x7524a8 in xmemdup0 /lib/util.c:168:15
    #3 0x73d8fc in smap_clone /lib/smap.c:314:45
    #4 0x576e2f in sync_dns_cache /controller/pinctrl.c:2513:13
    #5 0x5758fb in pinctrl_run /controller/pinctrl.c:3158:5
    #6 0x59b06c in main /controller/ovn-controller.c:2642:25
    #7 0x7fb570fc11a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)

Fixes: 6b72068 ("ovn-controller: Add a new thread in pinctrl module to handle packet-ins.")
Acked-by: Dumitru Ceara <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
Signed-off-by: Numan Siddique <[email protected]>
  • Loading branch information
igsilya authored and numansiddique committed Nov 22, 2020
1 parent d058d9a commit 79b946d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion controller/pinctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,7 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table)
dns_data->delete = false;

if (!smap_equal(&dns_data->records, &sbrec_dns->records)) {
smap_clear(&dns_data->records);
smap_destroy(&dns_data->records);
smap_clone(&dns_data->records, &sbrec_dns->records);
}

Expand All @@ -2525,6 +2525,8 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table)
struct dns_data *d = iter->data;
if (d->delete) {
shash_delete(&dns_cache, iter);
smap_destroy(&d->records);
free(d->dps);
free(d);
}
}
Expand All @@ -2537,6 +2539,8 @@ destroy_dns_cache(void)
SHASH_FOR_EACH_SAFE (iter, next, &dns_cache) {
struct dns_data *d = iter->data;
shash_delete(&dns_cache, iter);
smap_destroy(&d->records);
free(d->dps);
free(d);
}
}
Expand Down

0 comments on commit 79b946d

Please sign in to comment.