[PATCH v2 05/17] virfdstream: Use VIR_AUTOCLOSE()

Peter Krempa pkrempa at redhat.com
Thu Aug 20 08:26:47 UTC 2020


On Tue, Jul 07, 2020 at 21:46:23 +0200, Michal Privoznik wrote:
> Again, instead of closing FDs explicitly, we can automatically
> close them when they go out of their respective scopes.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/util/virfdstream.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

[...]

> @@ -1160,9 +1158,10 @@ int virFDStreamConnectUNIX(virStreamPtr st,
>  {
>      struct sockaddr_un sa;
>      virTimeBackOffVar timeout;
> +    VIR_AUTOCLOSE fd = -1;
>      int ret;
>  
> -    int fd = socket(AF_UNIX, SOCK_STREAM, 0);
> +    fd = socket(AF_UNIX, SOCK_STREAM, 0);
>      if (fd < 0) {
>          virReportSystemError(errno, "%s", _("Unable to open UNIX socket"));
>          goto error;
> @@ -1197,10 +1196,11 @@ int virFDStreamConnectUNIX(virStreamPtr st,
>  
>      if (virFDStreamOpenInternal(st, fd, NULL, 0) < 0)
>          goto error;
> +
> +    fd = -1;
>      return 0;

Please move the clearing of 'fd' closer towards the call to
'virFDStreamOpenInternal' which consumes it than to the return statement
so that it's visualy clearer that it's consumed by the call.


Reviewed-by: Peter Krempa <pkrempa at redhat.com>




More information about the libvir-list mailing list