From 5608070764a844ba6d1b6e751dade689fc0e75b7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 6 Dec 2022 14:17:29 +0100 Subject: [PATCH] nm-cloud-setup: simplify clearing variables in retry loop The label "try_again" is only reached by one goto. So it was correct and sufficient to reset the state only there. It is still error prone. The slighlty clearer approach is to clear the state at each begin of the "try_again" step. There should be no change in behavior. I didn't confirm, but an optimizing compiler should (could) be able to see that the cleanup is only necessary on retry, and generate the same code as before. In any case, we should write code that is easier to read, not optimize for something that a compiler should be able to optimize itself. (cherry picked from commit 911b55014082558ace27acc32853c45fdf09874e) --- src/nm-cloud-setup/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index 7a85350f4e..e1cbd1d4d8 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -494,6 +494,8 @@ _config_one(GCancellable *sigterm_cancellable, try_count = 0; try_again: + g_clear_object(&applied_connection); + g_clear_error(&error); applied_connection = nmcs_device_get_applied_connection(device, sigterm_cancellable, @@ -567,8 +569,6 @@ try_again: &error)) { if (version_id_changed && try_count < 5) { _LOGD("config device %s: applied connection changed in the meantime. Retry...", hwaddr); - g_clear_object(&applied_connection); - g_clear_error(&error); try_count++; goto try_again; }