All of lore.kernel.org
 help / color / mirror / Atom feed
* Memory leak in obexd/plugins/opp.c
@ 2011-08-06 10:40 Daniele Forsi
  2011-08-09  7:50 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Daniele Forsi @ 2011-08-06 10:40 UTC (permalink / raw)
  To: linux-bluetooth

cppcheck shows this:
[./plugins/opp.c:146]: (error) Memory leak: folder

I'm not sending a patch because I can't test it and it seems that the
g_strdup()'s can be removed because the folder and name variables are
only used as arguments to g_build_filename()
-- 
Daniele Forsi

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

* Re: Memory leak in obexd/plugins/opp.c
  2011-08-06 10:40 Memory leak in obexd/plugins/opp.c Daniele Forsi
@ 2011-08-09  7:50 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2011-08-09  7:50 UTC (permalink / raw)
  To: Daniele Forsi; +Cc: linux-bluetooth

Hi Daniele,

On Sat, Aug 6, 2011 at 1:40 PM, Daniele Forsi <dforsi@gmail.com> wrote:
> cppcheck shows this:
> [./plugins/opp.c:146]: (error) Memory leak: folder
>
> I'm not sending a patch because I can't test it and it seems that the
> g_strdup()'s can be removed because the folder and name variables are
> only used as arguments to g_build_filename()

Thanks for reporting this, in fact both folder and name ('\0') seems
to be leaking, they are always allocated because of
manager_request_authorization can return new strings. I think the
following should fix the problem:

diff --git a/plugins/opp.c b/plugins/opp.c
index 644a2c6..fd78af4 100644
--- a/plugins/opp.c
+++ b/plugins/opp.c
@@ -142,8 +142,10 @@ static int opp_chkput(struct obex_session *os,
void *user_data)
                name = g_strdup(obex_get_name(os));

 skip_auth:
-       if (name == NULL || strlen(name) == 0)
-               return -EBADR;
+       if (name == NULL || strlen(name) == 0) {
+               ret = -EBADR;
+               goto failed;
+       }

        if (g_strcmp0(name, obex_get_name(os)) != 0)
                obex_set_name(os, name);
@@ -155,6 +157,8 @@ skip_auth:
        ret = obex_put_stream_start(os, path);

        g_free(path);
+
+failed:
        g_free(folder);
        g_free(name);


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2011-08-09  7:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-06 10:40 Memory leak in obexd/plugins/opp.c Daniele Forsi
2011-08-09  7:50 ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.