anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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