]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: don't accidentally unref a varlink connection twice 18986/head
authorLennart Poettering <lennart@poettering.net>
Fri, 12 Mar 2021 21:21:58 +0000 (22:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 May 2021 19:45:32 +0000 (21:45 +0200)
Let's make sure that our close handler unrefs a connection again that we
are already unreffing a few stack frames up by invalidating the pointer
first, and dropping the ref counter only after that.

Replaces: 39ad3f1c092b5dffcbb4b1d12eb9ca407f010a3c

Fixes: #18025
src/core/core-varlink.c

index b3df8cd893c099b36c85ef3e338999b83f922bbf..b7afb87d500575f5ce3ba306bd0bbb43a3f8ed98 100644 (file)
@@ -475,8 +475,11 @@ int manager_varlink_init(Manager *m) {
 void manager_varlink_done(Manager *m) {
         assert(m);
 
-        /* Send the final message if we still have a subscribe request open. */
-        m->managed_oom_varlink_request = varlink_close_unref(m->managed_oom_varlink_request);
+        /* Explicitly close the varlink connection to oomd. Note we first take the varlink connection out of
+         * the manager, and only then disconnect it — in two steps – so that we don't end up accidentally
+         * unreffing it twice. After all, closing the connection might cause the disconnect handler we
+         * installed (vl_disconnect() above) to be called, where we will unref it too. */
+        varlink_close_unref(TAKE_PTR(m->managed_oom_varlink_request));
 
         m->varlink_server = varlink_server_unref(m->varlink_server);
 }