From c0df8f834aec7ca7ae3737813c487566a90b873a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 26 Jul 2018 17:33:23 +0900 Subject: [PATCH 1/2] resolve: fix memleak --- src/resolve/resolved-etc-hosts.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 507f68b47f..08591661f6 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -79,7 +79,7 @@ static const struct hash_ops etc_hosts_item_ops = { }; static int add_item(Manager *m, int family, const union in_addr_union *address, char **names) { - + _cleanup_strv_free_ char **dummy = names; EtcHostsItem key = { .family = family, .address = *address, @@ -125,6 +125,8 @@ static int add_item(Manager *m, int family, const union in_addr_union *address, free(item); return log_oom(); } + + dummy = NULL; } } From 52588e0bda2895326a63b9c9178adafceadabfa1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 26 Jul 2018 17:43:09 +0900 Subject: [PATCH 2/2] resolve: use structured initialization and use new() instead of new0() --- src/resolve/resolved-etc-hosts.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 08591661f6..10e2b7f737 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -112,13 +112,15 @@ static int add_item(Manager *m, int family, const union in_addr_union *address, if (r < 0) return log_oom(); - item = new0(EtcHostsItem, 1); + item = new(EtcHostsItem, 1); if (!item) return log_oom(); - item->family = family; - item->address = *address; - item->names = names; + *item = (EtcHostsItem) { + .family = family, + .address = *address, + .names = names, + }; r = set_put(m->etc_hosts_by_address, item); if (r < 0) {