public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez PATCH ] Fix memory leaks in obex
@ 2021-05-15 13:43 Steve Grubb
  2021-05-17 17:10 ` Tedd Ho-Jeong An
  2021-05-19 18:09 ` Luiz Augusto von Dentz
  0 siblings, 2 replies; 4+ messages in thread
From: Steve Grubb @ 2021-05-15 13:43 UTC (permalink / raw)
  To: linux-bluetooth

This patch fixes a couple memory leaks.

In filesystem, g_file_get_contents allocates fresh memory to buf.
It needs to be freed after conversion to a GString object.

Destination was missed on an error path as is mld.

---
 obexd/plugins/filesystem.c     | 2 +-
 obexd/plugins/ftp.c            | 8 ++++++--
 obexd/plugins/messages-dummy.c | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
index 09bff8ad0..44e3cf3d2 100644
--- a/obexd/plugins/filesystem.c
+++ b/obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode,
 		}
 
 		object->buffer = g_string_new(buf);
+		g_free(buf);
 
 		if (size)
 			*size = object->buffer->len;
diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
index 259bfcae2..4b04bab06 100644
--- a/obexd/plugins/ftp.c
+++ b/obexd/plugins/ftp.c
@@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name,
 	ret = verify_path(destdir);
 	g_free(destdir);
 
-	if (ret < 0)
+	if (ret < 0) {
+		g_free(destination);
 		return ret;
+	}
 
 	source = g_build_filename(ftp->folder, name, NULL);
 
@@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name,
 	ret = verify_path(destdir);
 	g_free(destdir);
 
-	if (ret < 0)
+	if (ret < 0) {
+		g_free(destination);
 		return ret;
+	}
 
 	source = g_build_filename(ftp->folder, name, NULL);
 
diff --git a/obexd/plugins/messages-dummy.c b/obexd/plugins/messages-dummy.c
index 34199fa05..e37b52df6 100644
--- a/obexd/plugins/messages-dummy.c
+++ b/obexd/plugins/messages-dummy.c
@@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name,
 			int err = -errno;
 			DBG("fopen(): %d, %s", -err, strerror(-err));
 			g_free(path);
+			g_free(mld);
 			return -EBADR;
 		}
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Bluez PATCH ] Fix memory leaks in obex
  2021-05-15 13:43 [Bluez PATCH ] Fix memory leaks in obex Steve Grubb
@ 2021-05-17 17:10 ` Tedd Ho-Jeong An
  2021-05-17 17:17   ` Steve Grubb
  2021-05-19 18:09 ` Luiz Augusto von Dentz
  1 sibling, 1 reply; 4+ messages in thread
From: Tedd Ho-Jeong An @ 2021-05-17 17:10 UTC (permalink / raw)
  To: Steve Grubb, linux-bluetooth

Hi Steve,

On Sat, 2021-05-15 at 09:43 -0400, Steve Grubb wrote:
> This patch fixes a couple memory leaks.
> 
> In filesystem, g_file_get_contents allocates fresh memory to buf.
> It needs to be freed after conversion to a GString object.
> 
> Destination was missed on an error path as is mld.
> 
> ---
>  obexd/plugins/filesystem.c     | 2 +-
>  obexd/plugins/ftp.c            | 8 ++++++--
>  obexd/plugins/messages-dummy.c | 1 +
>  3 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
> index 09bff8ad0..44e3cf3d2 100644
> --- a/obexd/plugins/filesystem.c
> +++ b/obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode,

CI wasn't able to apply the patch and couldn't run the tests, and I think because of this line.


>  		}
>  
>  		object->buffer = g_string_new(buf);
> +		g_free(buf);
>  
>  		if (size)
>  			*size = object->buffer->len;
> diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
> index 259bfcae2..4b04bab06 100644
> --- a/obexd/plugins/ftp.c
> +++ b/obexd/plugins/ftp.c
> @@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name,
>  	ret = verify_path(destdir);
>  	g_free(destdir);
>  
> -	if (ret < 0)
> +	if (ret < 0) {
> +		g_free(destination);
>  		return ret;
> +	}
>  
>  	source = g_build_filename(ftp->folder, name, NULL);
>  
> @@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name,
>  	ret = verify_path(destdir);
>  	g_free(destdir);
>  
> -	if (ret < 0)
> +	if (ret < 0) {
> +		g_free(destination);
>  		return ret;
> +	}
>  
>  	source = g_build_filename(ftp->folder, name, NULL);
>  
> diff --git a/obexd/plugins/messages-dummy.c b/obexd/plugins/messages-dummy.c
> index 34199fa05..e37b52df6 100644
> --- a/obexd/plugins/messages-dummy.c
> +++ b/obexd/plugins/messages-dummy.c
> @@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name,
>  			int err = -errno;
>  			DBG("fopen(): %d, %s", -err, strerror(-err));
>  			g_free(path);
> +			g_free(mld);
>  			return -EBADR;
>  		}
>  	}


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bluez PATCH ] Fix memory leaks in obex
  2021-05-17 17:10 ` Tedd Ho-Jeong An
@ 2021-05-17 17:17   ` Steve Grubb
  0 siblings, 0 replies; 4+ messages in thread
From: Steve Grubb @ 2021-05-17 17:17 UTC (permalink / raw)
  To: linux-bluetooth, Tedd Ho-Jeong An

On Monday, May 17, 2021 1:10:58 PM EDT Tedd Ho-Jeong An wrote:
> On Sat, 2021-05-15 at 09:43 -0400, Steve Grubb wrote:
> > This patch fixes a couple memory leaks.
> > 
> > In filesystem, g_file_get_contents allocates fresh memory to buf.
> > It needs to be freed after conversion to a GString object.
> > 
> > Destination was missed on an error path as is mld.
> > 
> > ---
> > obexd/plugins/filesystem.c     | 2 +-
> > obexd/plugins/ftp.c            | 8 ++++++--
> > obexd/plugins/messages-dummy.c | 1 +
> > 3 files changed, 8 insertions(+), 3 deletions(-)
> > 
> > diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
> > index 09bff8ad0..44e3cf3d2 100644
> > --- a/obexd/plugins/filesystem.c
> > +++ b/obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void
> > *capability_open(const char *name, int oflag, mode_t mode,
>
> CI wasn't able to apply the patch and couldn't run the tests, and I think
> because of this line.

Hmm. Apologies. I'll regenerate the patch and send it again.

Cheers,
-Steve



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bluez PATCH ] Fix memory leaks in obex
  2021-05-15 13:43 [Bluez PATCH ] Fix memory leaks in obex Steve Grubb
  2021-05-17 17:10 ` Tedd Ho-Jeong An
@ 2021-05-19 18:09 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2021-05-19 18:09 UTC (permalink / raw)
  To: Steve Grubb; +Cc: linux-bluetooth@vger.kernel.org

Hi Steve,

On Sat, May 15, 2021 at 7:16 PM Steve Grubb <sgrubb@redhat.com> wrote:
>
> This patch fixes a couple memory leaks.
>
> In filesystem, g_file_get_contents allocates fresh memory to buf.
> It needs to be freed after conversion to a GString object.
>
> Destination was missed on an error path as is mld.
>
> ---
>  obexd/plugins/filesystem.c     | 2 +-
>  obexd/plugins/ftp.c            | 8 ++++++--
>  obexd/plugins/messages-dummy.c | 1 +
>  3 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
> index 09bff8ad0..44e3cf3d2 100644
> --- a/obexd/plugins/filesystem.c
> +++ b/obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode,
>                 }
>
>                 object->buffer = g_string_new(buf);
> +               g_free(buf);
>
>                 if (size)
>                         *size = object->buffer->len;
> diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
> index 259bfcae2..4b04bab06 100644
> --- a/obexd/plugins/ftp.c
> +++ b/obexd/plugins/ftp.c
> @@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name,
>         ret = verify_path(destdir);
>         g_free(destdir);
>
> -       if (ret < 0)
> +       if (ret < 0) {
> +               g_free(destination);
>                 return ret;
> +       }
>
>         source = g_build_filename(ftp->folder, name, NULL);
>
> @@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name,
>         ret = verify_path(destdir);
>         g_free(destdir);
>
> -       if (ret < 0)
> +       if (ret < 0) {
> +               g_free(destination);
>                 return ret;
> +       }
>
>         source = g_build_filename(ftp->folder, name, NULL);
>
> diff --git a/obexd/plugins/messages-dummy.c b/obexd/plugins/messages-dummy.c
> index 34199fa05..e37b52df6 100644
> --- a/obexd/plugins/messages-dummy.c
> +++ b/obexd/plugins/messages-dummy.c
> @@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name,
>                         int err = -errno;
>                         DBG("fopen(): %d, %s", -err, strerror(-err));
>                         g_free(path);
> +                       g_free(mld);
>                         return -EBADR;
>                 }
>         }
> --
> 2.31.1

Applied, thanks.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-19 18:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-15 13:43 [Bluez PATCH ] Fix memory leaks in obex Steve Grubb
2021-05-17 17:10 ` Tedd Ho-Jeong An
2021-05-17 17:17   ` Steve Grubb
2021-05-19 18:09 ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox