提交 ab54d5f1 编写于 作者: J John Ferlan

secret: Clean up virSecretObjListExport logic

Shorten the time needed to keep the list lock and alter the cleanup
path to be more of an error path.

Utilize the the virObjectListFree function to handle the calls for
virObjectUnref on each list element and the VIR_FREE of the list
instead of open coding it.

Change the name of the virHashForEach callback to match the name
of the Export function with the Callback added onto it.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 891d0a76
......@@ -527,9 +527,9 @@ struct virSecretObjListData {
};
static int
virSecretObjListPopulate(void *payload,
const void *name ATTRIBUTE_UNUSED,
void *opaque)
virSecretObjListExportCallback(void *payload,
const void *name ATTRIBUTE_UNUSED,
void *opaque)
{
struct virSecretObjListData *data = opaque;
virSecretObjPtr obj = payload;
......@@ -573,7 +573,6 @@ virSecretObjListExport(virConnectPtr conn,
virSecretObjListACLFilter filter,
unsigned int flags)
{
int ret = -1;
struct virSecretObjListData data = {
.conn = conn, .secrets = NULL,
.filter = filter, .flags = flags,
......@@ -581,30 +580,28 @@ virSecretObjListExport(virConnectPtr conn,
virObjectLock(secretobjs);
if (secrets &&
VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0)
goto cleanup;
VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) {
virObjectUnlock(secretobjs);
return -1;
}
virHashForEach(secretobjs->objs, virSecretObjListPopulate, &data);
virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
virObjectUnlock(secretobjs);
if (data.error)
goto cleanup;
goto error;
if (data.secrets) {
/* trim the array to the final size */
ignore_value(VIR_REALLOC_N(data.secrets, data.nsecrets + 1));
*secrets = data.secrets;
data.secrets = NULL;
}
ret = data.nsecrets;
return data.nsecrets;
cleanup:
virObjectUnlock(secretobjs);
while (data.secrets && data.nsecrets)
virObjectUnref(data.secrets[--data.nsecrets]);
VIR_FREE(data.secrets);
return ret;
error:
virObjectListFree(data.secrets);
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册