Skip to contentSkip to conversation

mesh: Fix various valgrind identified problems

PATCH In review Brian Gix 1 participant 5 messages Dec 3, 2019 – Dec 4, 2019 Bluetooth drivers

lore
Share & tools
lore

Brian Gix

author
#0 lore raw

v2 cover mesh: Fix various valgrind identified problems

This patchset addresses a few valgrind identified errors, including some instances where memory was used after freeing. All three patches relate to the memory allocated for Provisioning purposes.

This includes the patch from Prathyusha that fixes close indication.

Brian Gix (2):
mesh: Rearrange PB-ACK for possible session close
mesh: Fix memory leak in Join() API call

Prathyusha N (1):
mesh: Fix to send close indication on timeout

 mesh/mesh.c          |  7 +++++--
 mesh/net.c           |  1 -
 mesh/pb-adv.c        | 10 ++++------
 mesh/prov-acceptor.c |  1 +
 4 files changed, 10 insertions(+), 9 deletions(-)
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH v2 1/3 mesh: Fix to send close indication on timeout

From: Prathyusha N <[email protected]>

If pb_session is freed in timeout, close indication will not be sent. pb_session is freed in pb_adv_unreg() and hence removed from tx_timeout. Added acceptor_free() in acp_prov_close() to ensure pb_session is freed.

---
 mesh/pb-adv.c        | 2 --
 mesh/prov-acceptor.c | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)
mesh/pb-adv.c +0 -2
index 19d14532a..586cd7f15 100644
@@ -175,8 +175,6 @@ static void tx_timeout(struct l_timeout *timeout, void *user_data)
 	l_info("TX timeout");
 	cb = pb_session->close_cb;
 	user_data = pb_session->user_data;
-	l_free(pb_session);
-	pb_session = NULL;
 	cb(user_data, 1);
 }
 
mesh/prov-acceptor.c +1 -0
index bca019358..03972c227 100644
@@ -121,6 +121,7 @@ static void acceptor_free(void)
 static void acp_prov_close(void *user_data, uint8_t reason)
 {
 	/* TODO: Handle Close */
+	acceptor_free();
 }
 
 static void prov_to(struct l_timeout *timeout, void *user_data)
Signature · 1 line
2.21.0
author
#2 lore raw

PATCH v2 2/3 mesh: Rearrange PB-ACK for possible session close

In reply to Brian Gix

In certain circumstances, reception of PB-ADV messages may trigger session close. This rearrange ACKs new verified messages before performing call-back to avoid situations where the session no longer exists after the message has been handled.

This caused static analysis errors during provisioning, which are now addressed.

---
 mesh/net.c    | 1 -
 mesh/pb-adv.c | 8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)
mesh/net.c +0 -1
index 61dd8be32..a60327272 100644
@@ -2381,7 +2381,6 @@ static enum _relay_advice packet_received(void *user_data,
 		l_info("RX: App 0x%04x -> 0x%04x : TTL 0x%02x : SEQ 0x%06x",
 					net_src, net_dst, net_ttl, net_seq);
 
-		l_debug("seq:%x seq0:%x", net_seq, net_seqZero);
 		if (net_ctl) {
 			l_debug("CTL - %4.4x RX", net_seqZero);
 			if (net_opcode == NET_OP_SEG_ACKNOWLEDGE) {
mesh/pb-adv.c +4 -4
index 586cd7f15..27cbc469e 100644
@@ -254,7 +254,7 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
 	uint8_t type;
 	bool first;
 
-	if (!session || pb_session != session)
+	if (!pb_session || pb_session != session)
 		return;
 
 	link_id = l_get_be32(pkt + 1);
@@ -426,14 +426,14 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
 			return;
 		}
 
+		send_ack(session, session->peer_trans_num);
+
 		if (session->last_peer_trans_num != session->peer_trans_num) {
 			session->got_segs = 0;
+			session->last_peer_trans_num = session->peer_trans_num;
 			session->rx_cb(session->user_data, session->sar,
 							session->exp_len);
 		}
-
-		session->last_peer_trans_num = session->peer_trans_num;
-		send_ack(session, session->last_peer_trans_num);
 	}
 }
 
Signature · 1 line
2.21.0
author
#3 lore raw

PATCH v2 3/3 mesh: Fix memory leak in Join() API call

In reply to Brian Gix
---
 mesh/mesh.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mesh/mesh.c +5 -2
index 432620a6a..6d2f86b6d 100644
@@ -71,7 +71,7 @@ struct bt_mesh {
 struct join_data{
 	struct l_dbus_message *msg;
 	struct mesh_agent *agent;
-	const char *sender;
+	char *sender;
 	const char *app_path;
 	struct mesh_node *node;
 	uint32_t disc_watch;
@@ -310,6 +310,7 @@ static void free_pending_join_call(bool failed)
 	if (failed)
 		node_remove(join_pending->node);
 
+	l_free(join_pending->sender);
 	l_free(join_pending);
 	join_pending = NULL;
 }
@@ -373,8 +374,10 @@ static void prov_disc_cb(struct l_dbus *bus, void *user_data)
 	if (!join_pending)
 		return;
 
-	if (join_pending->msg)
+	if (join_pending->msg) {
 		l_dbus_message_unref(join_pending->msg);
+		join_pending->msg = NULL;
+	}
 
 	acceptor_cancel(&mesh);
 	join_pending->disc_watch = 0;
Signature · 1 line
2.21.0
author
#4 lore raw
In reply to Brian Gix

Patchset Applied

Quoted 19 lines · Brian Gix

This patchset addresses a few valgrind identified errors, including some instances where memory was used after freeing. All three patches relate to the memory allocated for Provisioning purposes.

This includes the patch from Prathyusha that fixes close indication.

Brian Gix (2):
mesh: Rearrange PB-ACK for possible session close
mesh: Fix memory leak in Join() API call

Prathyusha N (1):
mesh: Fix to send close indication on timeout

 mesh/mesh.c          |  7 +++++--
 mesh/net.c           |  1 -
 mesh/pb-adv.c        | 10 ++++------
 mesh/prov-acceptor.c |  1 +
 4 files changed, 10 insertions(+), 9 deletions(-)