ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
803fb7
From c724e008771aaaed70f909cb28fdcab1c9244d22 Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Mon, 18 May 2015 23:23:17 +0200
803fb7
Subject: [PATCH] resolved: fix crash when shutting down
803fb7
MIME-Version: 1.0
803fb7
Content-Type: text/plain; charset=UTF-8
803fb7
Content-Transfer-Encoding: 8bit
803fb7
803fb7
Reported by Cristian Rodríguez
803fb7
803fb7
http://lists.freedesktop.org/archives/systemd-devel/2015-May/031626.html
803fb7
(cherry picked from commit cab5b05903096e1c9cf5575ccc73f89d15c8db69)
803fb7
803fb7
Cherry-picked from: cab5b05
803fb7
Resolves: #1222517
803fb7
---
803fb7
 src/resolve/resolved-dns-cache.c  |  4 +---
803fb7
 src/resolve/resolved-dns-server.c | 15 ++++++++-------
803fb7
 src/resolve/resolved-link.c       |  6 +++---
803fb7
 src/resolve/resolved-manager.c    |  4 ++--
803fb7
 src/shared/prioq.c                |  6 ++++--
803fb7
 src/shared/prioq.h                |  2 +-
803fb7
 6 files changed, 19 insertions(+), 18 deletions(-)
803fb7
803fb7
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
803fb7
index 33ca4d1a4..874207cfb 100644
803fb7
--- a/src/resolve/resolved-dns-cache.c
803fb7
+++ b/src/resolve/resolved-dns-cache.c
803fb7
@@ -93,9 +93,7 @@ void dns_cache_flush(DnsCache *c) {
803fb7
 
803fb7
         hashmap_free(c->by_key);
803fb7
         c->by_key = NULL;
803fb7
-
803fb7
-        prioq_free(c->by_expiry);
803fb7
-        c->by_expiry = NULL;
803fb7
+        c->by_expiry = prioq_free(c->by_expiry);
803fb7
 }
803fb7
 
803fb7
 static void dns_cache_remove(DnsCache *c, DnsResourceKey *key) {
803fb7
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
803fb7
index caf06fe45..9a62a6325 100644
803fb7
--- a/src/resolve/resolved-dns-server.c
803fb7
+++ b/src/resolve/resolved-dns-server.c
803fb7
@@ -78,23 +78,24 @@ DnsServer* dns_server_free(DnsServer *s)  {
803fb7
         if (!s)
803fb7
                 return NULL;
803fb7
 
803fb7
-        if (s->manager) {
803fb7
+        if (s->link) {
803fb7
                 if (s->type == DNS_SERVER_LINK)
803fb7
                         LIST_REMOVE(servers, s->link->dns_servers, s);
803fb7
-                else if (s->type == DNS_SERVER_SYSTEM)
803fb7
+
803fb7
+                if (s->link->current_dns_server == s)
803fb7
+                        link_set_dns_server(s->link, NULL);
803fb7
+        }
803fb7
+
803fb7
+        if (s->manager) {
803fb7
+                if (s->type == DNS_SERVER_SYSTEM)
803fb7
                         LIST_REMOVE(servers, s->manager->dns_servers, s);
803fb7
                 else if (s->type == DNS_SERVER_FALLBACK)
803fb7
                         LIST_REMOVE(servers, s->manager->fallback_dns_servers, s);
803fb7
-                else
803fb7
-                        assert_not_reached("Unknown server type");
803fb7
 
803fb7
                 if (s->manager->current_dns_server == s)
803fb7
                         manager_set_dns_server(s->manager, NULL);
803fb7
         }
803fb7
 
803fb7
-        if (s->link && s->link->current_dns_server == s)
803fb7
-                link_set_dns_server(s->link, NULL);
803fb7
-
803fb7
         free(s);
803fb7
 
803fb7
         return NULL;
803fb7
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
803fb7
index f94e4bb6f..27d9129e0 100644
803fb7
--- a/src/resolve/resolved-link.c
803fb7
+++ b/src/resolve/resolved-link.c
803fb7
@@ -68,13 +68,13 @@ Link *link_free(Link *l) {
803fb7
         if (l->manager)
803fb7
                 hashmap_remove(l->manager->links, INT_TO_PTR(l->ifindex));
803fb7
 
803fb7
+        while (l->dns_servers)
803fb7
+                dns_server_free(l->dns_servers);
803fb7
+
803fb7
         dns_scope_free(l->unicast_scope);
803fb7
         dns_scope_free(l->llmnr_ipv4_scope);
803fb7
         dns_scope_free(l->llmnr_ipv6_scope);
803fb7
 
803fb7
-        while (l->dns_servers)
803fb7
-                dns_server_free(l->dns_servers);
803fb7
-
803fb7
         free(l);
803fb7
         return NULL;
803fb7
 }
803fb7
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
803fb7
index b5ad70161..7c253aa13 100644
803fb7
--- a/src/resolve/resolved-manager.c
803fb7
+++ b/src/resolve/resolved-manager.c
803fb7
@@ -536,11 +536,11 @@ Manager *manager_free(Manager *m) {
803fb7
         while (m->dns_queries)
803fb7
                 dns_query_free(m->dns_queries);
803fb7
 
803fb7
-        dns_scope_free(m->unicast_scope);
803fb7
-
803fb7
         manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
803fb7
         manager_flush_dns_servers(m, DNS_SERVER_FALLBACK);
803fb7
 
803fb7
+        dns_scope_free(m->unicast_scope);
803fb7
+
803fb7
         hashmap_free(m->links);
803fb7
         hashmap_free(m->dns_transactions);
803fb7
 
803fb7
diff --git a/src/shared/prioq.c b/src/shared/prioq.c
803fb7
index 8af4c51c2..b89888be0 100644
803fb7
--- a/src/shared/prioq.c
803fb7
+++ b/src/shared/prioq.c
803fb7
@@ -45,12 +45,14 @@ Prioq *prioq_new(compare_func_t compare_func) {
803fb7
         return q;
803fb7
 }
803fb7
 
803fb7
-void prioq_free(Prioq *q) {
803fb7
+Prioq* prioq_free(Prioq *q) {
803fb7
         if (!q)
803fb7
-                return;
803fb7
+                return NULL;
803fb7
 
803fb7
         free(q->items);
803fb7
         free(q);
803fb7
+
803fb7
+        return NULL;
803fb7
 }
803fb7
 
803fb7
 int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func) {
803fb7
diff --git a/src/shared/prioq.h b/src/shared/prioq.h
803fb7
index d836b36cd..1c044b135 100644
803fb7
--- a/src/shared/prioq.h
803fb7
+++ b/src/shared/prioq.h
803fb7
@@ -28,7 +28,7 @@ typedef struct Prioq Prioq;
803fb7
 #define PRIOQ_IDX_NULL ((unsigned) -1)
803fb7
 
803fb7
 Prioq *prioq_new(compare_func_t compare);
803fb7
-void prioq_free(Prioq *q);
803fb7
+Prioq *prioq_free(Prioq *q);
803fb7
 int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func);
803fb7
 
803fb7
 int prioq_put(Prioq *q, void *data, unsigned *idx);