diff --git a/src/machine/machine.c b/src/machine/machine.c index b5d017a671..c6475a5398 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -355,6 +355,7 @@ static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_er return log_error_errno(r, "Failed to start machine scope: %s", bus_error_message(error, r)); m->unit = TAKE_PTR(scope); + m->referenced = true; free_and_replace(m->scope_job, job); } @@ -422,9 +423,12 @@ static int machine_stop_scope(Machine *m) { } else free_and_replace(m->scope_job, job); - q = manager_unref_unit(m->manager, m->unit, &error); - if (q < 0) - log_warning_errno(q, "Failed to drop reference to machine scope, ignoring: %s", bus_error_message(&error, r)); + if (m->referenced) { + q = manager_unref_unit(m->manager, m->unit, &error); + if (q < 0) + log_warning_errno(q, "Failed to drop reference to machine scope, ignoring: %s", bus_error_message(&error, r)); + m->referenced = false; + } return r; } diff --git a/src/machine/machine.h b/src/machine/machine.h index f7471be8f5..0a39e61052 100644 --- a/src/machine/machine.h +++ b/src/machine/machine.h @@ -54,6 +54,7 @@ struct Machine { bool in_gc_queue:1; bool started:1; bool stopping:1; + bool referenced:1; sd_bus_message *create_message;