提交 f11e9abe 编写于 作者: J Ján Tomko

testutils: use g_autoptr

Use g_autoptr where possible.

virTestCapsBuildNUMATopology is not converted completely,
because while the VIR_FREE call on cell_cpus is technically
wrong, neither VIR_ALLOC_N nor virBitmapNew can return
an allocation error now so it is effectively dead code.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 40656ff7
...@@ -418,7 +418,7 @@ virTestRewrapFile(const char *filename) ...@@ -418,7 +418,7 @@ virTestRewrapFile(const char *filename)
{ {
int ret = -1; int ret = -1;
g_autofree char *script = NULL; g_autofree char *script = NULL;
virCommandPtr cmd = NULL; g_autoptr(virCommand) cmd = NULL;
if (!(virStringHasSuffix(filename, ".args") || if (!(virStringHasSuffix(filename, ".args") ||
virStringHasSuffix(filename, ".ldargs"))) virStringHasSuffix(filename, ".ldargs")))
...@@ -432,7 +432,6 @@ virTestRewrapFile(const char *filename) ...@@ -432,7 +432,6 @@ virTestRewrapFile(const char *filename)
ret = 0; ret = 0;
cleanup: cleanup:
virCommandFree(cmd);
return ret; return ret;
} }
...@@ -1001,7 +1000,7 @@ void virTestClearCommandPath(char *cmdset) ...@@ -1001,7 +1000,7 @@ void virTestClearCommandPath(char *cmdset)
virCapsPtr virTestGenericCapsInit(void) virCapsPtr virTestGenericCapsInit(void)
{ {
virCapsPtr caps; g_autoptr(virCaps) caps = NULL;
virCapsGuestPtr guest; virCapsGuestPtr guest;
if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64, if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64,
...@@ -1047,10 +1046,9 @@ virCapsPtr virTestGenericCapsInit(void) ...@@ -1047,10 +1046,9 @@ virCapsPtr virTestGenericCapsInit(void)
VIR_TEST_DEBUG("Generic driver capabilities:\n%s", caps_str); VIR_TEST_DEBUG("Generic driver capabilities:\n%s", caps_str);
} }
return caps; return g_steal_pointer(&caps);
error: error:
virObjectUnref(caps);
return NULL; return NULL;
} }
...@@ -1066,7 +1064,7 @@ virCapsPtr virTestGenericCapsInit(void) ...@@ -1066,7 +1064,7 @@ virCapsPtr virTestGenericCapsInit(void)
virCapsHostNUMAPtr virCapsHostNUMAPtr
virTestCapsBuildNUMATopology(int seq) virTestCapsBuildNUMATopology(int seq)
{ {
virCapsHostNUMAPtr caps = virCapabilitiesHostNUMANew(); g_autoptr(virCapsHostNUMA) caps = virCapabilitiesHostNUMANew();
virCapsHostNUMACellCPUPtr cell_cpus = NULL; virCapsHostNUMACellCPUPtr cell_cpus = NULL;
int core_id, cell_id; int core_id, cell_id;
int id; int id;
...@@ -1096,10 +1094,9 @@ virTestCapsBuildNUMATopology(int seq) ...@@ -1096,10 +1094,9 @@ virTestCapsBuildNUMATopology(int seq)
cell_cpus = NULL; cell_cpus = NULL;
} }
return caps; return g_steal_pointer(&caps);
error: error:
virCapabilitiesHostNUMAUnref(caps);
VIR_FREE(cell_cpus); VIR_FREE(cell_cpus);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册