[Qemu-devel] [PATCH] gdbstub: Prevent fd leakage

Philippe Mathieu-Daudé posted 1 patch 7 years, 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180524223458.5651-1-f4bug@amsat.org
Test checkpatch passed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test s390x passed
gdbstub.c | 1 +
1 file changed, 1 insertion(+)
[Qemu-devel] [PATCH] gdbstub: Prevent fd leakage
Posted by Philippe Mathieu-Daudé 7 years, 8 months ago
Since 2f652224f7, we now check if socket_set_nodelay() errored,
but forgot to close the socket before reporting an error.

Fixes: Coverity CID 1391290 (RESOURCE_LEAK)
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 gdbstub.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gdbstub.c b/gdbstub.c
index e4ece2f5bc..9c860cd81c 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1836,6 +1836,7 @@ static bool gdb_accept(void)
     /* set short latency */
     if (socket_set_nodelay(fd)) {
         perror("setsockopt");
+        close(fd);
         return false;
     }
 
-- 
2.17.0


Re: [Qemu-devel] [PATCH] gdbstub: Prevent fd leakage
Posted by Thomas Huth 7 years, 8 months ago
On 25.05.2018 00:34, Philippe Mathieu-Daudé wrote:
> Since 2f652224f7, we now check if socket_set_nodelay() errored,
> but forgot to close the socket before reporting an error.
> 
> Fixes: Coverity CID 1391290 (RESOURCE_LEAK)
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  gdbstub.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index e4ece2f5bc..9c860cd81c 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1836,6 +1836,7 @@ static bool gdb_accept(void)
>      /* set short latency */
>      if (socket_set_nodelay(fd)) {
>          perror("setsockopt");
> +        close(fd);
>          return false;
>      }

Reviewed-by: Thomas Huth <thuth@redhat.com>

Re: [Qemu-devel] [PATCH] gdbstub: Prevent fd leakage
Posted by Peter Maydell 7 years, 8 months ago
On 24 May 2018 at 23:34, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Since 2f652224f7, we now check if socket_set_nodelay() errored,
> but forgot to close the socket before reporting an error.
>
> Fixes: Coverity CID 1391290 (RESOURCE_LEAK)
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  gdbstub.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index e4ece2f5bc..9c860cd81c 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1836,6 +1836,7 @@ static bool gdb_accept(void)
>      /* set short latency */
>      if (socket_set_nodelay(fd)) {
>          perror("setsockopt");
> +        close(fd);
>          return false;
>      }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM