On 4/7/25 15:24, Peter Krempa via Devel wrote:
> From: Peter Krempa <pkre...@redhat.com>
> 
> Use 'g_autfree' for the two temporary strings.
> 
> 'sysfs_cpudir' was used in two places, one of which is in a loop. Add
> another helper variable for it and declare the other one in the loop.
> 
> Signed-off-by: Peter Krempa <pkre...@redhat.com>
> ---
>  src/util/virhostcpu.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
> index 3b4a11effb..c4138076d9 100644
> --- a/src/util/virhostcpu.c
> +++ b/src/util/virhostcpu.c
> @@ -644,8 +644,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
>      int threads_per_subcore = 0;
>      unsigned int node;
>      int ret = -1;
> -    char *sysfs_nodedir = NULL;
> -    char *sysfs_cpudir = NULL;
> +    g_autofree char *sysfs_nodedir = NULL;
> +    g_autofree char *sysfs_cpudir_fallback = NULL;
>      int direrr;
> 
>      *mhz = 0;
> @@ -707,6 +707,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
>          threads_per_subcore = 0;
> 
>      while ((direrr = virDirRead(nodedir, &nodedirent, sysfs_nodedir)) > 0) {
> +        char *sysfs_cpudir = NULL;

Surely you meant g_autofree ;-)

> +
>          if (sscanf(nodedirent->d_name, "node%u", &node) != 1)
>              continue;
> 
> @@ -723,8 +725,6 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
>                                              &nodethreads, &offline)) < 0)
>              goto cleanup;
> 
> -        VIR_FREE(sysfs_cpudir);
> -
>          *cpus += nodecpus;
> 
>          if (nodesockets > *sockets)
> @@ -744,11 +744,9 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
>          goto done;
> 
>   fallback:
> -    VIR_FREE(sysfs_cpudir);
> -
> -    sysfs_cpudir = g_strdup_printf("%s/cpu", SYSFS_SYSTEM_PATH);
> +    sysfs_cpudir_fallback = g_strdup_printf("%s/cpu", SYSFS_SYSTEM_PATH);
> 
> -    if ((nodecpus = virHostCPUParseNode(sysfs_cpudir, arch,
> +    if ((nodecpus = virHostCPUParseNode(sysfs_cpudir_fallback, arch,
>                                          present_cpus_map,
>                                          online_cpus_map,
>                                          threads_per_subcore,
> @@ -799,8 +797,6 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
>      ret = 0;
> 
>   cleanup:
> -    VIR_FREE(sysfs_nodedir);
> -    VIR_FREE(sysfs_cpudir);
>      return ret;
>  }
> 

Michal

Reply via email to