PATCH [2/2] batostr(): Replace batostr() where possible with ba2str to avoid memleaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



batostr() returns a dynamically allocated string which must be freed
later, although, the function looks like the standard berkeley socket
functions that work on static buffers. Two functions inside bluez
incorrectly use batostr() and do not free the returned pointer. I
replaced the occurrence of batostr() with a ba2str().

This makes batostr() unused throughout whole bluez so it may be
removed. However, I don't know whether we should keep it to keep
backwards compatibility.

Patch is against most recent git plus PATCH [1/2]. Patch file is also
attached as x-patch file.

David

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

[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux