[Spice-devel] [PATCH linux vdagent] Avoid leaking fd when udscs_create_server_for_fd fails

Victor Toso victortoso at redhat.com
Fri Dec 1 15:03:20 UTC 2017


Hi,

On Wed, Nov 29, 2017 at 11:48:43AM -0600, Jonathon Jongsma wrote:
> Reported by Frediano Ziglio. if udscs_create_server_for_fd() fails, it
> will return NULL and the file descriptor will be leaked. Since the
> calling function is the one that created the fd, it should free the fd
> if the server could not be created.
> 
> Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
kj
> ---
>  src/udscs.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/src/udscs.c b/src/udscs.c
> index 6e73015..c439f23 100644
> --- a/src/udscs.c
> +++ b/src/udscs.c
> @@ -438,6 +438,7 @@ struct udscs_server *udscs_create_server(const char *socketname,
>      int c;
>      int fd;
>      struct sockaddr_un address;
> +    struct udscs_server *server;
>  
>      fd = socket(PF_UNIX, SOCK_STREAM, 0);
>      if (fd == -1) {
> @@ -461,9 +462,15 @@ struct udscs_server *udscs_create_server(const char *socketname,
>          return NULL;
>      }
>  
> -    return udscs_create_server_for_fd(fd, connect_callback, read_callback,
> -                                      disconnect_callback, type_to_string,
> -                                      no_types, debug);
> +    server = udscs_create_server_for_fd(fd, connect_callback, read_callback,
> +                                        disconnect_callback, type_to_string,
> +                                        no_types, debug);
> +
> +    if (!server) {
> +        close(fd);
> +    }
> +
> +    return server;
>  }
>  
>  void udscs_destroy_server(struct udscs_server *server)
> -- 
> 2.13.6
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20171201/f5b1b3fe/attachment.sig>


More information about the Spice-devel mailing list