Replace batostr() with ba2str() to avoid memleaks
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
@@ -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
@@ -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
Hi David,
Quoted 7 lines · David Herrmann
batostr()returns dynamically allocated strings. Replace it withba2str()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