virsysinfo: Define and use auto cleanup func for virSysinfoDef properly

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: cee3a900a0
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2021-03-11 06:17:07 +01:00
parent 52a937d8a2
commit ab9afee6e7
3 changed files with 6 additions and 6 deletions

View 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;

View 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);

View 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;