linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Replace batostr() with ba2str() to avoid memleaks
@ 2011-02-17 23:06 David Herrmann
  2011-02-18 15:02 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: David Herrmann @ 2011-02-17 23:06 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, David Herrmann

batostr() returns dynamically allocated strings. Replace it with
ba2str() wherever possible to avoid heap allocations and fix
memleaks.
---
 compat/bnep.c |    5 +++--
 test/hciemu.c |    4 +++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/compat/bnep.c b/compat/bnep.c
index 9b0d8b8..3617e0e 100644
--- a/compat/bnep.c
+++ b/compat/bnep.c
@@ -128,6 +128,7 @@ int bnep_show_connections(void)
 	struct bnep_connlist_req req;
 	struct bnep_conninfo ci[48];
 	unsigned int i;
+	char buf[18];
 
 	req.cnum = 48;
 	req.ci   = ci;
@@ -137,9 +138,9 @@ int bnep_show_connections(void)
 	}
 
 	for (i = 0; i < req.cnum; i++) {
+		ba2str((bdaddr_t*)ci[i].dst, buf);
 		printf("%s %s %s\n", ci[i].device,
-			batostr((bdaddr_t *) ci[i].dst),
-			bnep_svc2str(ci[i].role));
+			buf, bnep_svc2str(ci[i].role));
 	}
 	return 0;
 }
diff --git a/test/hciemu.c b/test/hciemu.c
index ba9b89d..db7c613 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -499,8 +499,10 @@ static void accept_connection(uint8_t *data)
 
 static void close_connection(struct vhci_conn *conn)
 {
+	char buf[18];
+	ba2str(&conn->dest, buf);
 	syslog(LOG_INFO, "Closing connection %s handle %d",
-					batostr(&conn->dest), conn->handle);
+					buf, conn->handle);
 
 	g_io_channel_shutdown(conn->chan, TRUE, NULL);
 	g_io_channel_unref(conn->chan);
-- 
1.7.4.1


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

* Re: [PATCH] Replace batostr() with ba2str() to avoid memleaks
  2011-02-17 23:06 [PATCH] Replace batostr() with ba2str() to avoid memleaks David Herrmann
@ 2011-02-18 15:02 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2011-02-18 15:02 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, David Herrmann

Hi David,

On Fri, Feb 18, 2011, David Herrmann wrote:
> batostr() returns dynamically allocated strings. Replace it with
> ba2str() wherever possible to avoid heap allocations and fix
> memleaks.
> ---
>  compat/bnep.c |    5 +++--
>  test/hciemu.c |    4 +++-
>  2 files changed, 6 insertions(+), 3 deletions(-)

Thanks. The patch has been pushed upstream with a couple of minor coding
style corrections.

Johan

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

end of thread, other threads:[~2011-02-18 15:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-17 23:06 [PATCH] Replace batostr() with ba2str() to avoid memleaks David Herrmann
2011-02-18 15:02 ` Johan Hedberg

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).