Skip to contentSkip to conversation

attrib-server: Fix memory leak attaching attribute channels

PATCH In review Santiago Carot-Nemesio 3 participants 5 messages Feb 7, 2012 – Feb 9, 2012 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 attrib-server: Fix memory leak attaching attribute channels

Channel is not being released when the channel is attached over an uninitialized GATT server.

---
 src/attrib-server.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
src/attrib-server.c +7 -1
index 2995167..e51f695 100644
@@ -1020,8 +1020,14 @@ guint attrib_channel_attach(GAttrib *attrib, gboolean out)
 	}
 
 	server = find_gatt_server(&channel->src);
-	if (server == NULL)
+	if (server == NULL) {
+		char src[18];
+
+		ba2str(&channel->src, src);
+		error("No GATT server found in %s", src);
+		g_free(channel);
 		return 0;
+	}
 
 	channel->server = server;
 
Signature · 1 line
1.7.9
#1 lore raw

PATCH 2/2 attrib-server: Fix bad error message

---
 src/attrib-server.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/attrib-server.c +1 -1
index e51f695..93a7b4f 100644
@@ -171,7 +171,7 @@ static struct gatt_server *find_gatt_server(const bdaddr_t *bdaddr)
 		char addr[18];
 
 		ba2str(bdaddr, addr);
-		error("Not GATT adapter found for address %s", addr);
+		error("No GATT server found in %s", addr);
 		return NULL;
 	}
 
Signature · 1 line
1.7.9
#2 lore raw
In reply to Santiago Carot-Nemesio

Hi Santiago,

Quoted 11 lines · Santiago Carot-Nemesio

Channel is not being released when the channel is attached over an uninitialized GATT server.

---
 src/attrib-server.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
src/attrib-server.c +0 -0
index 2995167..e51f695 100644

src/attrib-server.c guint attrib_channel_attach(GAttrib *attrib, gboolean out) · line 1024

Quoted 6 lines
src/attrib-server.c +2 -1
@@ -1020,8 +1020,14 @@ guint attrib_channel_attach(GAttrib *attrib, gboolean out)
 	}
 
 	server = find_gatt_server(&channel->src);
-	if (server == NULL)
+	if (server == NULL) {
+		char src[18];

Don't we have a good define for this magic number? I saw it in several places.

Best regards
Andrei Emeltchenko

#3 lore raw

Hi Andrei,

2012/2/8 Andrei Emeltchenko <[email protected]>:

Quoted 16 lines

Hi Santiago,

Quoted 13 lines · Santiago Carot-Nemesio

Channel is not being released when the channel is attached over an uninitialized GATT server.
---
 src/attrib-server.c |    8 +++++++-

 1 files changed, 7 insertions(+), 1 deletions(-)
src/attrib-server.c +0 -0
index 2995167..e51f695 100644
@@ -1020,8 +1020,14 @@ guint attrib_channel_attach(GAttrib *attrib, gboolean out)
       }
 
Quoted 8 lines

src/attrib-server.c guint attrib_channel_attach(GAttrib *attrib, gboolean out) · line 1024

Quoted 4 lines
src/attrib-server.c +2 -1
       server = find_gatt_server(&channel->src);
-     if (server == NULL)
+     if (server == NULL) {
+             char src[18];

Don't we have a good define for this magic number? I saw it in several places.

That's a good point, I've also seen it in too many places but I don't know if there is any macro for that, at least I didn't see it.

Regards.

#4 lore raw
In reply to Santiago Carot-Nemesio

Hi Santiago,

Quoted 5 lines · Santiago Carot-Nemesio

Channel is not being released when the channel is attached over an uninitialized GATT server.

---
 src/attrib-server.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

Both patches have been applied. Thanks.

Johan