Re: [PATCH v1 29/32] util: process: use VIR_AUTOFREE instead of VIR_FREE for scalar types

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

 



On Sat, Jul 28, 2018 at 11:31:44PM +0530, Sukrit Bhatnagar wrote:
> By making use of GNU C's cleanup attribute handled by the
> VIR_AUTOFREE macro for declaring scalar variables, majority
> of the VIR_FREE calls can be dropped, which in turn leads to
> getting rid of most of our cleanup sections.
>
> Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx>
> ---
>  src/util/virprocess.c | 49 ++++++++++++++++++++++++-------------------------
>  1 file changed, 24 insertions(+), 25 deletions(-)
>

> @@ -475,7 +473,11 @@ virBitmapPtr
>  virProcessGetAffinity(pid_t pid)
>  {
>      size_t i;
> +# ifdef CPU_ALLOC
>      cpu_set_t *mask;
> +# else
> +    VIR_AUTOFREE(cpu_set_t *) mask = NULL;
> +# endif
>      size_t masklen;
>      size_t ncpus;
>      virBitmapPtr ret = NULL;
> @@ -504,11 +506,20 @@ virProcessGetAffinity(pid_t pid)
>      if (sched_getaffinity(pid, masklen, mask) < 0) {
>          virReportSystemError(errno,
>                               _("cannot get CPU affinity of process %d"), pid);
> +# ifdef CPU_ALLOC
>          goto cleanup;
> +# else
> +        return ret;
> +# endif
>      }
>
>      if (!(ret = virBitmapNew(ncpus)))
> -          goto cleanup;
> +# ifdef CPU_ALLOC
> +
> +        goto cleanup;
> +# else
> +        return ret;
> +# endif
>
>      for (i = 0; i < ncpus; i++) {
>  # ifdef CPU_ALLOC
> @@ -522,11 +533,7 @@ virProcessGetAffinity(pid_t pid)
>      }
>
>   cleanup:
> -# ifdef CPU_ALLOC
>      CPU_FREE(mask);
> -# else
> -    VIR_FREE(mask);
> -# endif

So instead of 1 conditional compile-time block we'd end up with 3, I don't
think that's a good idea, better leave it as is. We could potentially
conditionally define VIR_DEFINE_AUTOPTR_FUNC handling these both cases, however
I don't particularly like that approach either, so let's leave this hunk out.

To the rest:
Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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