qemu-trivial
[Top][All Lists]
Advanced

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

Re: [PATCH] virtfs-proxy-helper: Fix a resource leak in main()


From: Li Qiang
Subject: Re: [PATCH] virtfs-proxy-helper: Fix a resource leak in main()
Date: Thu, 26 Nov 2020 18:50:29 +0800

Alex Chen <alex.chen@huawei.com> 于2020年11月26日周四 下午6:29写道:
>
> Only one of the options -s and -f can be used. When -f is used,
> the fd is created externally and does not need to be closed.
> When -s is used, a new socket fd is created, and this socket fd
> needs to be closed at the end of main().
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>
> ---
>  fsdev/virtfs-proxy-helper.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
> index 15c0e79b06..339d477169 100644
> --- a/fsdev/virtfs-proxy-helper.c
> +++ b/fsdev/virtfs-proxy-helper.c
> @@ -1154,6 +1154,9 @@ int main(int argc, char **argv)
>      process_requests(sock);
>  error:
>      g_free(rpath);
> +    if (sock_name) {
> +        close(sock);
> +    }

If 'proxy_socket' failed, you call close(-1).

Maybe following is better?

if (sock >= 0) {
    close(sock);
}

Thanks,
Li Qiang

>      g_free(sock_name);
>      do_log(LOG_INFO, "Done\n");
>      closelog();
> --
> 2.19.1
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]