teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0207-resolved-fix-crash-when-shutting-down.patch

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