public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] mesh: Fix memory leak on dbus message creation
@ 2019-07-03 16:34 Brian Gix
  2019-07-03 17:24 ` Michał Lowas-Rzechonek
  0 siblings, 1 reply; 2+ messages in thread
From: Brian Gix @ 2019-07-03 16:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: inga.stotland, brian.gix, michal.lowas-rzechonek

---
 mesh/model.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mesh/model.c b/mesh/model.c
index 7401dcecb..a2b3e5c18 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -729,10 +729,13 @@ static void send_msg_rcvd(struct mesh_node *node, uint8_t ele_idx, bool is_sub,
 	if (!l_dbus_message_builder_finalize(builder))
 		goto error;
 
+	l_dbus_message_builder_destroy(builder);
 	l_dbus_send(dbus, msg);
+	return;
 
 error:
 	l_dbus_message_builder_destroy(builder);
+	l_dbus_message_unref(msg);
 }
 
 bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
-- 
2.14.5


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

* Re: [PATCH BlueZ] mesh: Fix memory leak on dbus message creation
  2019-07-03 16:34 [PATCH BlueZ] mesh: Fix memory leak on dbus message creation Brian Gix
@ 2019-07-03 17:24 ` Michał Lowas-Rzechonek
  0 siblings, 0 replies; 2+ messages in thread
From: Michał Lowas-Rzechonek @ 2019-07-03 17:24 UTC (permalink / raw)
  To: Brian Gix; +Cc: linux-bluetooth, inga.stotland

Hi,

On 07/03, Brian Gix wrote:
> ---
>  mesh/model.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mesh/model.c b/mesh/model.c
> index 7401dcecb..a2b3e5c18 100644
> --- a/mesh/model.c
> +++ b/mesh/model.c
> @@ -729,10 +729,13 @@ static void send_msg_rcvd(struct mesh_node *node, uint8_t ele_idx, bool is_sub,
>  	if (!l_dbus_message_builder_finalize(builder))
>  		goto error;
>  
> +	l_dbus_message_builder_destroy(builder);
>  	l_dbus_send(dbus, msg);
> +	return;
>  
>  error:
>  	l_dbus_message_builder_destroy(builder);
> +	l_dbus_message_unref(msg);
>  }
>  
>  bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,

Since in ELL's dbus API it's legal to unref a NULL message, I'd rather
write this as:

    l_dbus_send(dbus, msg);
    msg = NULL;

error:
    l_dbus_message_builder_destroy(builder);
    l_dbus_message_unref(msg);


or (version for purists):

    l_dbus_send(dbus, msg);
    msg = NULL;

error:
    l_dbus_message_builder_destroy(builder);
    if (msg)
        l_dbus_message_unref(msg);


mostly to emphasize that l_dbus_send has "move" semantics.

-- 
Michał Lowas-Rzechonek <michal.lowas-rzechonek@silvair.com>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND

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

end of thread, other threads:[~2019-07-03 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03 16:34 [PATCH BlueZ] mesh: Fix memory leak on dbus message creation Brian Gix
2019-07-03 17:24 ` Michał Lowas-Rzechonek

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