[systemd-commits] src/resolve src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Mon May 18 14:24:11 PDT 2015


 src/resolve/resolved-dns-cache.c  |    7 ++-----
 src/resolve/resolved-dns-server.c |   15 ++++++++-------
 src/resolve/resolved-link.c       |    6 +++---
 src/resolve/resolved-manager.c    |    4 ++--
 src/shared/prioq.c                |    6 ++++--
 src/shared/prioq.h                |    2 +-
 6 files changed, 20 insertions(+), 20 deletions(-)

New commits:
commit cab5b05903096e1c9cf5575ccc73f89d15c8db69
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon May 18 23:23:17 2015 +0200

    resolved: fix crash when shutting down
    
    Reported by Cristian Rodríguez
    
    http://lists.freedesktop.org/archives/systemd-devel/2015-May/031626.html

diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index 33ca4d1..be52891 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -91,11 +91,8 @@ void dns_cache_flush(DnsCache *c) {
         assert(hashmap_size(c->by_key) == 0);
         assert(prioq_size(c->by_expiry) == 0);
 
-        hashmap_free(c->by_key);
-        c->by_key = NULL;
-
-        prioq_free(c->by_expiry);
-        c->by_expiry = NULL;
+        c->by_key = hashmap_free(c->by_key);
+        c->by_expiry = prioq_free(c->by_expiry);
 }
 
 static void dns_cache_remove(DnsCache *c, DnsResourceKey *key) {
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index caf06fe..9a62a63 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -78,23 +78,24 @@ DnsServer* dns_server_free(DnsServer *s)  {
         if (!s)
                 return NULL;
 
-        if (s->manager) {
+        if (s->link) {
                 if (s->type == DNS_SERVER_LINK)
                         LIST_REMOVE(servers, s->link->dns_servers, s);
-                else if (s->type == DNS_SERVER_SYSTEM)
+
+                if (s->link->current_dns_server == s)
+                        link_set_dns_server(s->link, NULL);
+        }
+
+        if (s->manager) {
+                if (s->type == DNS_SERVER_SYSTEM)
                         LIST_REMOVE(servers, s->manager->dns_servers, s);
                 else if (s->type == DNS_SERVER_FALLBACK)
                         LIST_REMOVE(servers, s->manager->fallback_dns_servers, s);
-                else
-                        assert_not_reached("Unknown server type");
 
                 if (s->manager->current_dns_server == s)
                         manager_set_dns_server(s->manager, NULL);
         }
 
-        if (s->link && s->link->current_dns_server == s)
-                link_set_dns_server(s->link, NULL);
-
         free(s);
 
         return NULL;
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index f94e4bb..27d9129 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -68,13 +68,13 @@ Link *link_free(Link *l) {
         if (l->manager)
                 hashmap_remove(l->manager->links, INT_TO_PTR(l->ifindex));
 
+        while (l->dns_servers)
+                dns_server_free(l->dns_servers);
+
         dns_scope_free(l->unicast_scope);
         dns_scope_free(l->llmnr_ipv4_scope);
         dns_scope_free(l->llmnr_ipv6_scope);
 
-        while (l->dns_servers)
-                dns_server_free(l->dns_servers);
-
         free(l);
         return NULL;
 }
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index dab737d..5269537 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -534,11 +534,11 @@ Manager *manager_free(Manager *m) {
         while (m->dns_queries)
                 dns_query_free(m->dns_queries);
 
-        dns_scope_free(m->unicast_scope);
-
         manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
         manager_flush_dns_servers(m, DNS_SERVER_FALLBACK);
 
+        dns_scope_free(m->unicast_scope);
+
         hashmap_free(m->links);
         hashmap_free(m->dns_transactions);
 
diff --git a/src/shared/prioq.c b/src/shared/prioq.c
index 8af4c51..b89888b 100644
--- a/src/shared/prioq.c
+++ b/src/shared/prioq.c
@@ -45,12 +45,14 @@ Prioq *prioq_new(compare_func_t compare_func) {
         return q;
 }
 
-void prioq_free(Prioq *q) {
+Prioq* prioq_free(Prioq *q) {
         if (!q)
-                return;
+                return NULL;
 
         free(q->items);
         free(q);
+
+        return NULL;
 }
 
 int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func) {
diff --git a/src/shared/prioq.h b/src/shared/prioq.h
index d836b36..1c044b1 100644
--- a/src/shared/prioq.h
+++ b/src/shared/prioq.h
@@ -28,7 +28,7 @@ typedef struct Prioq Prioq;
 #define PRIOQ_IDX_NULL ((unsigned) -1)
 
 Prioq *prioq_new(compare_func_t compare);
-void prioq_free(Prioq *q);
+Prioq *prioq_free(Prioq *q);
 int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func);
 
 int prioq_put(Prioq *q, void *data, unsigned *idx);



More information about the systemd-commits mailing list