virDomainDefValidateAliases: Refactor to avoid cleanup section
Use a temporary auto-freed local variable to hold the hash table so that the cleanup section can be removed. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
parent
5a661107ab
commit
a3c30eea3f
@ -1257,25 +1257,20 @@ static int
|
|||||||
virDomainDefValidateAliases(const virDomainDef *def,
|
virDomainDefValidateAliases(const virDomainDef *def,
|
||||||
GHashTable **aliases)
|
GHashTable **aliases)
|
||||||
{
|
{
|
||||||
struct virDomainDefValidateAliasesData data;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
/* We are not storing copies of aliases. Don't free them. */
|
/* We are not storing copies of aliases. Don't free them. */
|
||||||
data.aliases = virHashNew(NULL);
|
g_autoptr(GHashTable) tmpaliases = virHashNew(NULL);
|
||||||
|
struct virDomainDefValidateAliasesData data = { .aliases = tmpaliases };
|
||||||
|
|
||||||
if (virDomainDeviceInfoIterateFlags((virDomainDef *) def,
|
if (virDomainDeviceInfoIterateFlags((virDomainDef *) def,
|
||||||
virDomainDeviceDefValidateAliasesIterator,
|
virDomainDeviceDefValidateAliasesIterator,
|
||||||
DOMAIN_DEVICE_ITERATE_ALL_CONSOLES,
|
DOMAIN_DEVICE_ITERATE_ALL_CONSOLES,
|
||||||
&data) < 0)
|
&data) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (aliases)
|
if (aliases)
|
||||||
*aliases = g_steal_pointer(&data.aliases);
|
*aliases = g_steal_pointer(&tmpaliases);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virHashFree(data.aliases);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user