mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
util: firewall: use VIR_AUTOFREE instead of VIR_FREE for scalar types
By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
2ad0284627
commit
469da57cd6
@ -511,7 +511,7 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewall,
|
|||||||
virFirewallRulePtr rule,
|
virFirewallRulePtr rule,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char *arg;
|
VIR_AUTOFREE(char *) arg = NULL;
|
||||||
va_list list;
|
va_list list;
|
||||||
|
|
||||||
VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule);
|
VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule);
|
||||||
@ -525,13 +525,11 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewall,
|
|||||||
|
|
||||||
va_end(list);
|
va_end(list);
|
||||||
|
|
||||||
VIR_FREE(arg);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
firewall->err = ENOMEM;
|
firewall->err = ENOMEM;
|
||||||
va_end(list);
|
va_end(list);
|
||||||
VIR_FREE(arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -678,7 +676,7 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule,
|
|||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
int status;
|
int status;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *error = NULL;
|
VIR_AUTOFREE(char *) error = NULL;
|
||||||
|
|
||||||
if (!bin) {
|
if (!bin) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -702,11 +700,10 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule,
|
|||||||
if (ignoreErrors) {
|
if (ignoreErrors) {
|
||||||
VIR_DEBUG("Ignoring error running command");
|
VIR_DEBUG("Ignoring error running command");
|
||||||
} else {
|
} else {
|
||||||
char *args = virCommandToString(cmd);
|
VIR_AUTOFREE(char *) args = virCommandToString(cmd);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to apply firewall rules %s: %s"),
|
_("Failed to apply firewall rules %s: %s"),
|
||||||
NULLSTR(args), NULLSTR(error));
|
NULLSTR(args), NULLSTR(error));
|
||||||
VIR_FREE(args);
|
|
||||||
VIR_FREE(*output);
|
VIR_FREE(*output);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -714,7 +711,6 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(error);
|
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -807,12 +803,11 @@ virFirewallApplyRule(virFirewallPtr firewall,
|
|||||||
virFirewallRulePtr rule,
|
virFirewallRulePtr rule,
|
||||||
bool ignoreErrors)
|
bool ignoreErrors)
|
||||||
{
|
{
|
||||||
char *output = NULL;
|
VIR_AUTOFREE(char *) output = NULL;
|
||||||
|
VIR_AUTOFREE(char *) str = virFirewallRuleToString(rule);
|
||||||
char **lines = NULL;
|
char **lines = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *str = virFirewallRuleToString(rule);
|
|
||||||
VIR_INFO("Applying rule '%s'", NULLSTR(str));
|
VIR_INFO("Applying rule '%s'", NULLSTR(str));
|
||||||
VIR_FREE(str);
|
|
||||||
|
|
||||||
if (rule->ignoreErrors)
|
if (rule->ignoreErrors)
|
||||||
ignoreErrors = rule->ignoreErrors;
|
ignoreErrors = rule->ignoreErrors;
|
||||||
@ -857,7 +852,6 @@ virFirewallApplyRule(virFirewallPtr firewall,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virStringListFree(lines);
|
virStringListFree(lines);
|
||||||
VIR_FREE(output);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user