2014-01-23 09:07:28

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH] btproxy: Fix resource leak

From: Andrei Emeltchenko <[email protected]>

Close file descriptors before leaving.
---
tools/btproxy.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/btproxy.c b/tools/btproxy.c
index be81bae..3503148 100644
--- a/tools/btproxy.c
+++ b/tools/btproxy.c
@@ -680,8 +680,11 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}

- if (!setup_proxy(host_fd, false, dev_fd, true))
+ if (!setup_proxy(host_fd, false, dev_fd, true)) {
+ close(dev_fd);
+ close(host_fd);
return EXIT_FAILURE;
+ }
} else {
int server_fd;

--
1.8.3.2



2014-01-23 13:24:56

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] btproxy: Fix resource leak

Hi Andrei,

On Thu, Jan 23, 2014, Andrei Emeltchenko wrote:
> Close file descriptors before leaving.
> ---
> tools/btproxy.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)

Applied. Thanks.

Johan

2014-01-22 15:54:56

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] btproxy: Fix resource leak

Hi Andrei,

> Close file descriptors if setup_proxy fails.
> ---
> tools/btproxy.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/btproxy.c b/tools/btproxy.c
> index 4429a16..9f409c3 100644
> --- a/tools/btproxy.c
> +++ b/tools/btproxy.c
> @@ -330,8 +330,11 @@ static bool setup_proxy(int host_fd, bool host_shutdown,
> struct proxy *proxy;
>
> proxy = new0(struct proxy, 1);
> - if (!proxy)
> + if (!proxy) {
> + close(host_fd);
> + close(dev_fd);
> return NULL;
> + }

this is the wrong fix for this.

You are returning an error with side effects of closing the file descriptors. You need to leave the error handling of the parameters that got handed in to the caller. I fixed that upstream now.

Regards

Marcel


2014-01-22 13:52:10

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] btproxy: Fix resource leak

Hi Andrei,

On Wed, Jan 22, 2014, Andrei Emeltchenko wrote:
> Close file descriptors if setup_proxy fails.
> ---
> tools/btproxy.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)

Applied. Thanks.

Johan