Similarly to ADD_ARG, let's create an ADD_ARG_RETURN_ON_ERROR macro
which will simply return instead of going to a cleanup label.
By doing this, we can get rid of a few cleanup labels spread in the
code.
Signed-off-by: Fabiano FidĂȘncio <fidencio(a)redhat.com>
---
src/util/virfirewall.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index 6dace18bc4..d632f72502 100644
--- a/src/util/virfirewall.c
+++ b/src/util/virfirewall.c
@@ -328,6 +328,16 @@ void virFirewallFree(virFirewallPtr firewall)
rule->args[rule->argsLen++] = g_strdup(str); \
} while (0)
+#define ADD_ARG_RETURN_ON_ERROR(rule, str) \
+ do { \
+ if (VIR_RESIZE_N(rule->args, \
+ rule->argsAlloc, \
+ rule->argsLen, 1) < 0) \
+ return; \
+ \
+ rule->args[rule->argsLen++] = g_strdup(str); \
+ } while (0)
+
static virFirewallRulePtr
virFirewallAddRuleFullV(virFirewallPtr firewall,
virFirewallLayer layer,
@@ -490,10 +500,7 @@ void virFirewallRuleAddArg(virFirewallPtr firewall,
{
VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule);
- ADD_ARG(rule, arg);
-
- cleanup:
- return;
+ ADD_ARG_RETURN_ON_ERROR(rule, arg);
}
@@ -510,10 +517,7 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewall,
arg = g_strdup_vprintf(fmt, list);
va_end(list);
- ADD_ARG(rule, arg);
-
- cleanup:
- return;
+ ADD_ARG_RETURN_ON_ERROR(rule, arg);
}
@@ -524,12 +528,9 @@ void virFirewallRuleAddArgSet(virFirewallPtr firewall,
VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule);
while (*args) {
- ADD_ARG(rule, *args);
+ ADD_ARG_RETURN_ON_ERROR(rule, *args);
args++;
}
-
- cleanup:
- return;
}
--
2.24.1