[PATCH] util: convert char pointers to use g_autofree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Barrett Schonefeld <bschoney@xxxxxxxxxx>

additional conversions to the GLib API in src/util per issue #11.

files updated are:
- src/util/vircgroupv1.c
- src/util/virhostcpu.c
- src/util/virlockspace.c
- src/util/virmacmap.c
- src/util/virresctrl.c
- src/util/virsysinfo.c

Related issue: https://gitlab.com/libvirt/libvirt/-/issues/11

Signed-off-by: bschoney <bschoney@xxxxxxxxxx>
Signed-off-by: Barrett Schonefeld <bschoney@xxxxxxxxxx>
---
 src/util/vircgroupv1.c  |  3 +--
 src/util/virhostcpu.c   |  4 +---
 src/util/virlockspace.c |  6 ++----
 src/util/virmacmap.c    |  3 +--
 src/util/virresctrl.c   | 25 ++++++++-----------------
 src/util/virsysinfo.c   |  9 +++------
 6 files changed, 16 insertions(+), 34 deletions(-)

diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 731e9d61d4..984cd50409 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1549,7 +1549,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
                          unsigned long long *unevictable)
 {
     int ret = -1;
-    char *stat = NULL;
+    g_autofree char *stat = NULL;
     char *line = NULL;
     unsigned long long cacheVal = 0;
     unsigned long long activeAnonVal = 0;
@@ -1614,7 +1614,6 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
     ret = 0;
 
  cleanup:
-    VIR_FREE(stat);
     return ret;
 }
 
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c531d65f86..4f6c3390ce 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -87,7 +87,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
                           int *nparams)
 {
     const char *sysctl_name;
-    long *cpu_times;
+    g_autofree long *cpu_times = NULL;
     struct clockinfo clkinfo;
     size_t i, j, cpu_times_size, clkinfo_size;
     int cpu_times_num, offset, hz, stathz, ret = -1;
@@ -172,8 +172,6 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
     ret = 0;
 
  cleanup:
-    VIR_FREE(cpu_times);
-
     return ret;
 }
 
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index b90e13f506..71d5dfb83e 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -515,7 +515,7 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace,
                                const char *resname)
 {
     int ret = -1;
-    char *respath = NULL;
+    g_autofree char *respath = NULL;
 
     VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname);
 
@@ -538,7 +538,6 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace,
 
  cleanup:
     virMutexUnlock(&lockspace->lock);
-    VIR_FREE(respath);
     return ret;
 }
 
@@ -547,7 +546,7 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace,
                                const char *resname)
 {
     int ret = -1;
-    char *respath = NULL;
+    g_autofree char *respath = NULL;
 
     VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname);
 
@@ -575,7 +574,6 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace,
 
  cleanup:
     virMutexUnlock(&lockspace->lock);
-    VIR_FREE(respath);
     return ret;
 }
 
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index f9047d0fb1..e68742de10 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -129,7 +129,7 @@ static int
 virMacMapLoadFile(virMacMapPtr mgr,
                   const char *file)
 {
-    char *map_str = NULL;
+    g_autofree char *map_str = NULL;
     virJSONValuePtr map = NULL;
     int map_str_len = 0;
     size_t i;
@@ -189,7 +189,6 @@ virMacMapLoadFile(virMacMapPtr mgr,
 
     ret = 0;
  cleanup:
-    VIR_FREE(map_str);
     virJSONValueFree(map);
     return ret;
 }
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index d3087b98c1..1c2d175295 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -709,7 +709,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
 {
     int ret = -1;
     int rv = -1;
-    char *featurestr = NULL;
+    g_autofree char *featurestr = NULL;
     char **features = NULL;
     size_t nfeatures = 0;
     virResctrlInfoMongrpPtr info_monitor = NULL;
@@ -771,7 +771,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
 
     ret = 0;
  cleanup:
-    VIR_FREE(featurestr);
     g_strfreev(features);
     VIR_FREE(info_monitor);
     return ret;
@@ -1736,7 +1735,7 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
                         const char *groupname,
                         virResctrlAllocPtr *alloc)
 {
-    char *schemata = NULL;
+    g_autofree char *schemata = NULL;
     int rv = virFileReadValueString(&schemata,
                                     SYSFS_RESCTRL_PATH "/%s/schemata",
                                     groupname);
@@ -1753,11 +1752,9 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
     if (virResctrlAllocParse(resctrl, *alloc, schemata) < 0)
         goto error;
 
-    VIR_FREE(schemata);
     return 0;
 
  error:
-    VIR_FREE(schemata);
     virObjectUnref(*alloc);
     *alloc = NULL;
     return -1;
@@ -2354,8 +2351,8 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
                       virResctrlAllocPtr alloc,
                       const char *machinename)
 {
-    char *schemata_path = NULL;
-    char *alloc_str = NULL;
+    g_autofree char *schemata_path = NULL;
+    g_autofree char *alloc_str = NULL;
     int ret = -1;
     int lockfd = -1;
 
@@ -2403,8 +2400,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
     ret = 0;
  cleanup:
     virResctrlUnlock(lockfd);
-    VIR_FREE(alloc_str);
-    VIR_FREE(schemata_path);
     return ret;
 }
 
@@ -2413,8 +2408,8 @@ static int
 virResctrlAddPID(const char *path,
                  pid_t pid)
 {
-    char *tasks = NULL;
-    char *pidstr = NULL;
+    g_autofree char *tasks = NULL;
+    g_autofree char *pidstr = NULL;
     int ret = 0;
 
     if (!path) {
@@ -2436,8 +2431,6 @@ virResctrlAddPID(const char *path,
 
     ret = 0;
  cleanup:
-    VIR_FREE(tasks);
-    VIR_FREE(pidstr);
     return ret;
 }
 
@@ -2657,8 +2650,8 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
     size_t i = 0;
     unsigned long long val = 0;
     g_autoptr(DIR) dirp = NULL;
-    char *datapath = NULL;
-    char *filepath = NULL;
+    g_autofree char *datapath = NULL;
+    g_autofree char *filepath = NULL;
     struct dirent *ent = NULL;
     virResctrlMonitorStatsPtr stat = NULL;
 
@@ -2737,8 +2730,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
 
     ret = 0;
  cleanup:
-    VIR_FREE(datapath);
-    VIR_FREE(filepath);
     virResctrlMonitorStatsFree(stat);
     return ret;
 }
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 217f842a37..e1336bf566 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -532,9 +532,9 @@ static int
 virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
 {
     const char *tmp_base;
-    char *manufacturer = NULL;
-    char *procline = NULL;
-    char *ncpu = NULL;
+    g_autofree char *manufacturer = NULL;
+    g_autofree char *procline = NULL;
+    g_autofree char *ncpu = NULL;
     int result = -1;
     virSysinfoProcessorDefPtr processor;
 
@@ -593,9 +593,6 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
     result = 0;
 
  error:
-    VIR_FREE(manufacturer);
-    VIR_FREE(procline);
-    VIR_FREE(ncpu);
     return result;
 }
 
-- 
2.29.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux