mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virStorageBackendRBDGetVolNames: Refactor cleanup in 'rbd_list' version
Use automatic memory freeing for the string list so that we can remove the cleanup section. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
361a18f405
commit
49d47342b3
@ -611,7 +611,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
|
|||||||
static char **
|
static char **
|
||||||
virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
|
virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
|
||||||
{
|
{
|
||||||
char **names = NULL;
|
g_auto(GStrv) names = NULL;
|
||||||
size_t nnames = 0;
|
size_t nnames = 0;
|
||||||
int rc;
|
int rc;
|
||||||
size_t max_size = 1024;
|
size_t max_size = 1024;
|
||||||
@ -626,7 +626,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
|
|||||||
break;
|
break;
|
||||||
if (rc != -ERANGE) {
|
if (rc != -ERANGE) {
|
||||||
virReportSystemError(errno, "%s", _("Unable to list RBD images"));
|
virReportSystemError(errno, "%s", _("Unable to list RBD images"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(namebuf);
|
VIR_FREE(namebuf);
|
||||||
}
|
}
|
||||||
@ -640,18 +640,14 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
|
|||||||
namedup = g_strdup(name);
|
namedup = g_strdup(name);
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(names, nnames, namedup) < 0)
|
if (VIR_APPEND_ELEMENT(names, nnames, namedup) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
name += strlen(name) + 1;
|
name += strlen(name) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_EXPAND_N(names, nnames, 1);
|
VIR_EXPAND_N(names, nnames, 1);
|
||||||
|
|
||||||
return names;
|
return g_steal_pointer(&names);
|
||||||
|
|
||||||
error:
|
|
||||||
virStringListFreeCount(names, nnames);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#endif /* ! WITH_RBD_LIST2 */
|
#endif /* ! WITH_RBD_LIST2 */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user