From 4ef0c13275fd1a7c1b86859cfada003670bbbe20 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Tue, 19 Mar 2019 15:14:13 +1030 Subject: [PATCH] mboxd: Tidy up failure paths on daemon startup Don't try to cleanup objects we haven't initialised. Change-Id: I218ab785af36bc3a1d3085c9dcd575e812402433 Signed-off-by: Andrew Jeffery --- mboxd.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/mboxd.c b/mboxd.c index 70580de..2026023 100644 --- a/mboxd.c +++ b/mboxd.c @@ -402,38 +402,38 @@ int main(int argc, char **argv) rc = init_signals(context, &set); if (rc) { - goto finish; + goto cleanup_context; } rc = mboxd_backend_init(context); if (rc) { - goto finish; + goto cleanup_context; } rc = protocol_init(context); if (rc) { - goto finish; + goto cleanup_backend; } rc = transport_mbox_init(context, &mbox_ops); if (rc) { - goto finish; + goto cleanup_protocol; } rc = lpc_dev_init(context); if (rc) { - goto finish; + goto cleanup_mbox; } /* We've found the reserved memory region -> we can assign to windows */ rc = windows_init(context); if (rc) { - goto finish; + goto cleanup_lpc; } rc = dbus_init(context, &dbus_ops); if (rc) { - goto finish; + goto cleanup_windows; } /* Set the LPC bus mapping */ @@ -446,12 +446,12 @@ int main(int argc, char **argv) /* Alert on all supported transports */ rc = protocol_events_put(context, mbox_ops); if (rc) { - goto finish; + goto cleanup; } rc = protocol_events_put(context, dbus_ops); if (rc) { - goto finish; + goto cleanup; } MSG_INFO("Entering Polling Loop\n"); @@ -459,7 +459,6 @@ int main(int argc, char **argv) MSG_INFO("Exiting Poll Loop: %d\n", rc); -finish: MSG_INFO("Daemon Exiting...\n"); context->bmc_events &= ~BMC_EVENT_DAEMON_READY; context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; @@ -468,12 +467,19 @@ finish: protocol_events_put(context, mbox_ops); protocol_events_put(context, dbus_ops); +cleanup: dbus_free(context); - backend_free(&context->backend); +cleanup_windows: + windows_free(context); +cleanup_lpc: lpc_dev_free(context); +cleanup_mbox: transport_mbox_free(context); - windows_free(context); +cleanup_protocol: protocol_free(context); +cleanup_backend: + backend_free(&context->backend); +cleanup_context: free(context); return rc; -- 2.30.2