summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-12-06 14:17:29 +0100
committerThomas Haller <thaller@redhat.com>2022-12-19 14:47:27 +0100
commit0d773e7930b33eee73c428121fb868e01cc1622b (patch)
tree7eedf6b8eef5e7a5347d81fe30525ead5aabd2a0
parentbd11de379c2905bd9f8b2c99497ca1d2830de1c0 (diff)
nm-cloud-setup: simplify clearing variables in retry loopth/cloud-setup-preserve-external-ip-1-40
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)
-rw-r--r--src/nm-cloud-setup/main.c4
1 files 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;
}