summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-12 22:21:58 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-15 19:54:55 +0200
commit0f5c532f174032c9b7ce31b16b9c29f45dcc3e72 (patch)
treec077321c2ff6438fae74af885955e420cf2f0d30
parente523386e198bd0729858f1c78ef808930ba12020 (diff)
downloadsystemd-0f5c532f174032c9b7ce31b16b9c29f45dcc3e72.tar.gz
core: don't accidentally unref a varlink connection twice
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 (cherry picked from commit d65e974e67e47222cdebd9d0b6becd6642547ce2) (cherry picked from commit 68da6997a9323c127a45ca019d32fa97ff0d7cca)
-rw-r--r--src/core/core-varlink.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/core/core-varlink.c b/src/core/core-varlink.c
index 96b378da8e..f08dac766f 100644
--- a/src/core/core-varlink.c
+++ b/src/core/core-varlink.c
@@ -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);
}