]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsysinfo: Define and use auto cleanup func for virSysinfoDef properly
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 11 Mar 2021 05:17:07 +0000 (06:17 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 15 Mar 2021 08:34:18 +0000 (09:34 +0100)
What we are using really is heap allocated structure rather than
stack allocated. And for that it's better to use g_autoptr() +
G_DEFINE_AUTOPTR_CLEANUP_FUNC() combo, as Glib documentation for
g_auto() reads:

  This is meant to be used with stack-allocated structures and
  non-pointer types. For the (more commonly used) pointer
  version, see g_autoptr().

This will be even more visible, when virSysinfoDefPtr type is
gone. Stay tuned.

Fixes: cee3a900a0d6a8fc79554db22dc262632fe487a6
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virsysinfo.c
src/util/virsysinfo.h
tests/sysinfotest.c

index 001602825401f362d33599b8c0a15eb833aa329c..1c8193cc583977e2b9d947fd8b3bfe598465ee74 100644 (file)
@@ -314,7 +314,7 @@ virSysinfoParsePPCProcessor(const char *base, virSysinfoDefPtr ret)
 virSysinfoDefPtr
 virSysinfoReadPPC(void)
 {
-    g_auto(virSysinfoDefPtr) ret = NULL;
+    g_autoptr(virSysinfoDef) ret = NULL;
     g_autofree char *outbuf = NULL;
 
     ret = g_new0(virSysinfoDef, 1);
@@ -436,7 +436,7 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
 virSysinfoDefPtr
 virSysinfoReadARM(void)
 {
-    g_auto(virSysinfoDefPtr) ret = NULL;
+    g_autoptr(virSysinfoDef) ret = NULL;
     g_autofree char *outbuf = NULL;
 
     /* Some ARM systems have DMI tables available. */
@@ -602,7 +602,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
 virSysinfoDefPtr
 virSysinfoReadS390(void)
 {
-    g_auto(virSysinfoDefPtr) ret = NULL;
+    g_autoptr(virSysinfoDef) ret = NULL;
     g_autofree char *outbuf = NULL;
 
     ret = g_new0(virSysinfoDef, 1);
@@ -1212,7 +1212,7 @@ virSysinfoParseX86Memory(const char *base, virSysinfoDefPtr ret)
 virSysinfoDefPtr
 virSysinfoReadDMI(void)
 {
-    g_auto(virSysinfoDefPtr) ret = NULL;
+    g_autoptr(virSysinfoDef) ret = NULL;
     g_autofree char *outbuf = NULL;
     g_autoptr(virCommand) cmd = NULL;
 
index 6b25969a4b94c06ff557f8fd9feeddb58c78bde5..6ae4ba7bf32fd139c6215f42e17a8e3c367b752b 100644 (file)
@@ -157,7 +157,7 @@ void virSysinfoChassisDefFree(virSysinfoChassisDefPtr def);
 void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDefPtr def);
 void virSysinfoDefFree(virSysinfoDefPtr def);
 
-G_DEFINE_AUTO_CLEANUP_FREE_FUNC(virSysinfoDefPtr, virSysinfoDefFree, NULL);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoDef, virSysinfoDefFree);
 
 int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
index 3b418955d0e249faaab1fef6c2c4187e423f43f2..e40a4564a7059ddef19a0e8e9f31f374a5a385d8 100644 (file)
@@ -91,7 +91,7 @@ testSysinfo(const void *data)
 {
     const struct testSysinfoData *testdata = data;
     const char *sysfsActualData;
-    g_auto(virSysinfoDefPtr) ret = NULL;
+    g_autoptr(virSysinfoDef) ret = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *sysinfo = NULL;
     g_autofree char *cpuinfo = NULL;