[libvirt PATCH 3/7] testutils: use g_autoptr

Ján Tomko posted 7 patches 6 years ago
[libvirt PATCH 3/7] testutils: use g_autoptr
Posted by Ján Tomko 6 years ago
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: Ján Tomko <jtomko@redhat.com>
---
 tests/testutils.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index 75cba98eb3..e9431b9b5f 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -418,7 +418,7 @@ virTestRewrapFile(const char *filename)
 {
     int ret = -1;
     g_autofree char *script = NULL;
-    virCommandPtr cmd = NULL;
+    g_autoptr(virCommand) cmd = NULL;
 
     if (!(virStringHasSuffix(filename, ".args") ||
           virStringHasSuffix(filename, ".ldargs")))
@@ -432,7 +432,6 @@ virTestRewrapFile(const char *filename)
 
     ret = 0;
  cleanup:
-    virCommandFree(cmd);
     return ret;
 }
 
@@ -1001,7 +1000,7 @@ void virTestClearCommandPath(char *cmdset)
 
 virCapsPtr virTestGenericCapsInit(void)
 {
-    virCapsPtr caps;
+    g_autoptr(virCaps) caps = NULL;
     virCapsGuestPtr guest;
 
     if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64,
@@ -1047,10 +1046,9 @@ virCapsPtr virTestGenericCapsInit(void)
         VIR_TEST_DEBUG("Generic driver capabilities:\n%s", caps_str);
     }
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virObjectUnref(caps);
     return NULL;
 }
 
@@ -1066,7 +1064,7 @@ virCapsPtr virTestGenericCapsInit(void)
 virCapsHostNUMAPtr
 virTestCapsBuildNUMATopology(int seq)
 {
-    virCapsHostNUMAPtr caps = virCapabilitiesHostNUMANew();
+    g_autoptr(virCapsHostNUMA) caps = virCapabilitiesHostNUMANew();
     virCapsHostNUMACellCPUPtr cell_cpus = NULL;
     int core_id, cell_id;
     int id;
@@ -1096,10 +1094,9 @@ virTestCapsBuildNUMATopology(int seq)
         cell_cpus = NULL;
     }
 
-    return caps;
+    return g_steal_pointer(&caps);
 
  error:
-    virCapabilitiesHostNUMAUnref(caps);
     VIR_FREE(cell_cpus);
     return NULL;
 }
-- 
2.21.1

Re: [libvirt PATCH 3/7] testutils: use g_autoptr
Posted by Daniel P. Berrangé 5 years, 12 months ago
On Sun, Feb 09, 2020 at 02:32:33AM +0100, Ján Tomko wrote:
> 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: Ján Tomko <jtomko@redhat.com>
> ---
>  tests/testutils.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|