Skip to contentSkip to conversation

Replace batostr() with ba2str() to avoid memleaks

PATCH In review David Herrmann 2 participants 2 messages Feb 17, 2011 – Feb 18, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Replace batostr() with ba2str() to avoid memleaks

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(-)
compat/bnep.c +3 -2
index 9b0d8b8..3617e0e 100644
@@ -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;
 }
test/hciemu.c +3 -1
index ba9b89d..db7c613 100644
@@ -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);
Signature · 1 line
1.7.4.1
#1 lore raw

Hi David,

Quoted 7 lines · 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(-)

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

Johan