linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] gdbus: Fix Memory Leak
@ 2015-12-01 13:11 Patrik Flykt
  2015-12-04 12:31 ` Von Dentz, Luiz
  0 siblings, 1 reply; 2+ messages in thread
From: Patrik Flykt @ 2015-12-01 13:11 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Von Dentz, Luiz, saurav.babu, connman

From: Saurav Babu <saurav.babu@samsung.com>

Members of data are allocated memory but not freed only data is freed
---

	Hi,

This patch came up on the ConnMan mailing list, applies to Bluez too.

	Patrik


 gdbus/watch.c | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index b60f650..447e486 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -204,6 +204,30 @@ static gboolean remove_match(struct filter_data *data)
 	return TRUE;
 }
 
+static void filter_data_free(struct filter_data *data)
+{
+	GSList *l;
+
+	/* Remove filter if there are no listeners left for the connection */
+	if (filter_data_find(data->connection) == NULL)
+		dbus_connection_remove_filter(data->connection, message_filter,
+									NULL);
+
+	for (l = data->callbacks; l != NULL; l = l->next)
+		g_free(l->data);
+
+	g_slist_free(data->callbacks);
+	g_dbus_remove_watch(data->connection, data->name_watch);
+	g_free(data->name);
+	g_free(data->owner);
+	g_free(data->path);
+	g_free(data->interface);
+	g_free(data->member);
+	g_free(data->argument);
+	dbus_connection_unref(data->connection);
+	g_free(data);
+}
+
 static struct filter_data *filter_data_get(DBusConnection *connection,
 					DBusHandleMessageFunction filter,
 					const char *sender,
@@ -248,7 +272,7 @@ proceed:
 	data->argument = g_strdup(argument);
 
 	if (!add_match(data, filter)) {
-		g_free(data);
+		filter_data_free(data);
 		return NULL;
 	}
 
@@ -277,30 +301,6 @@ static struct filter_callback *filter_data_find_callback(
 	return NULL;
 }
 
-static void filter_data_free(struct filter_data *data)
-{
-	GSList *l;
-
-	/* Remove filter if there are no listeners left for the connection */
-	if (filter_data_find(data->connection) == NULL)
-		dbus_connection_remove_filter(data->connection, message_filter,
-									NULL);
-
-	for (l = data->callbacks; l != NULL; l = l->next)
-		g_free(l->data);
-
-	g_slist_free(data->callbacks);
-	g_dbus_remove_watch(data->connection, data->name_watch);
-	g_free(data->name);
-	g_free(data->owner);
-	g_free(data->path);
-	g_free(data->interface);
-	g_free(data->member);
-	g_free(data->argument);
-	dbus_connection_unref(data->connection);
-	g_free(data);
-}
-
 static void filter_data_call_and_free(struct filter_data *data)
 {
 	GSList *l;
-- 
1.9.1

_______________________________________________
connman mailing list
connman@lists.01.org
https://lists.01.org/mailman/listinfo/connman



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

* Re: [PATCH v2 1/4] gdbus: Fix Memory Leak
  2015-12-01 13:11 [PATCH v2 1/4] gdbus: Fix Memory Leak Patrik Flykt
@ 2015-12-04 12:31 ` Von Dentz, Luiz
  0 siblings, 0 replies; 2+ messages in thread
From: Von Dentz, Luiz @ 2015-12-04 12:31 UTC (permalink / raw)
  To: Patrik Flykt; +Cc: linux-bluetooth@vger.kernel.org, saurav.babu, connman

Hi,

On Tue, Dec 1, 2015 at 3:11 PM, Patrik Flykt
<Patrik.Flykt@linux.intel.com> wrote:
> From: Saurav Babu <saurav.babu@samsung.com>
>
> Members of data are allocated memory but not freed only data is freed
> ---
>
>         Hi,
>
> This patch came up on the ConnMan mailing list, applies to Bluez too.
>
>         Patrik
>
>
>  gdbus/watch.c | 50 +++++++++++++++++++++++++-------------------------
>  1 file changed, 25 insertions(+), 25 deletions(-)
>
> diff --git a/gdbus/watch.c b/gdbus/watch.c
> index b60f650..447e486 100644
> --- a/gdbus/watch.c
> +++ b/gdbus/watch.c
> @@ -204,6 +204,30 @@ static gboolean remove_match(struct filter_data *data)
>         return TRUE;
>  }
>
> +static void filter_data_free(struct filter_data *data)
> +{
> +       GSList *l;
> +
> +       /* Remove filter if there are no listeners left for the connection */
> +       if (filter_data_find(data->connection) == NULL)
> +               dbus_connection_remove_filter(data->connection, message_filter,
> +                                                                       NULL);
> +
> +       for (l = data->callbacks; l != NULL; l = l->next)
> +               g_free(l->data);
> +
> +       g_slist_free(data->callbacks);
> +       g_dbus_remove_watch(data->connection, data->name_watch);
> +       g_free(data->name);
> +       g_free(data->owner);
> +       g_free(data->path);
> +       g_free(data->interface);
> +       g_free(data->member);
> +       g_free(data->argument);
> +       dbus_connection_unref(data->connection);
> +       g_free(data);
> +}
> +
>  static struct filter_data *filter_data_get(DBusConnection *connection,
>                                         DBusHandleMessageFunction filter,
>                                         const char *sender,
> @@ -248,7 +272,7 @@ proceed:
>         data->argument = g_strdup(argument);
>
>         if (!add_match(data, filter)) {
> -               g_free(data);
> +               filter_data_free(data);
>                 return NULL;
>         }
>
> @@ -277,30 +301,6 @@ static struct filter_callback *filter_data_find_callback(
>         return NULL;
>  }
>
> -static void filter_data_free(struct filter_data *data)
> -{
> -       GSList *l;
> -
> -       /* Remove filter if there are no listeners left for the connection */
> -       if (filter_data_find(data->connection) == NULL)
> -               dbus_connection_remove_filter(data->connection, message_filter,
> -                                                                       NULL);
> -
> -       for (l = data->callbacks; l != NULL; l = l->next)
> -               g_free(l->data);
> -
> -       g_slist_free(data->callbacks);
> -       g_dbus_remove_watch(data->connection, data->name_watch);
> -       g_free(data->name);
> -       g_free(data->owner);
> -       g_free(data->path);
> -       g_free(data->interface);
> -       g_free(data->member);
> -       g_free(data->argument);
> -       dbus_connection_unref(data->connection);
> -       g_free(data);
> -}
> -
>  static void filter_data_call_and_free(struct filter_data *data)
>  {
>         GSList *l;
> --
> 1.9.1

This has been applied to BlueZ.

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

end of thread, other threads:[~2015-12-04 12:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-01 13:11 [PATCH v2 1/4] gdbus: Fix Memory Leak Patrik Flykt
2015-12-04 12:31 ` Von Dentz, Luiz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).