You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/07/09 10:52:26 UTC

[GitHub] michal-narajowski closed pull request #139: mesh: Fix memory leaks when preparing messages

michal-narajowski closed pull request #139: mesh: Fix memory leaks when preparing messages
URL: https://github.com/apache/mynewt-nimble/pull/139
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/mesh/src/access.c b/nimble/host/mesh/src/access.c
index f7ced0bd..332385ba 100644
--- a/nimble/host/mesh/src/access.c
+++ b/nimble/host/mesh/src/access.c
@@ -165,10 +165,12 @@ static int publish_retransmit(struct bt_mesh_model *mod)
 		.xmit = bt_mesh_net_transmit_get(),
 		.friend_cred = pub->cred,
 	};
+	int err;
 
 	key = bt_mesh_app_key_find(pub->key);
 	if (!key) {
-		return -EADDRNOTAVAIL;
+		err = -EADDRNOTAVAIL;
+		goto done;
 	}
 
 	tx.sub = bt_mesh_subnet_get(key->net_idx);
@@ -181,7 +183,11 @@ static int publish_retransmit(struct bt_mesh_model *mod)
 
 	pub->count--;
 
-	return bt_mesh_trans_send(&tx, sdu, &pub_sent_cb, mod);
+	err = bt_mesh_trans_send(&tx, sdu, &pub_sent_cb, mod);
+
+done:
+	os_mbuf_free_chain(sdu);
+	return err;
 }
 
 static void mod_publish(struct ble_npl_event *work)
@@ -671,10 +677,10 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
 	err = model_send(model, &tx, true, sdu, &pub_sent_cb, model);
 	if (err) {
 		pub->count = 0;
-		return err;
 	}
 
-	return 0;
+	os_mbuf_free_chain(sdu);
+	return err;
 }
 
 struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem,
diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c
index ac106f36..b2cd4ed7 100644
--- a/nimble/host/mesh/src/friend.c
+++ b/nimble/host/mesh/src/friend.c
@@ -408,6 +408,7 @@ static struct os_mbuf *encode_update(struct bt_mesh_friend *frnd, u8_t md)
 	struct bt_mesh_ctl_friend_update *upd;
 	struct os_mbuf *sdu = NET_BUF_SIMPLE(1 + sizeof(*upd));
 	struct bt_mesh_subnet *sub = bt_mesh_subnet_get(frnd->net_idx);
+	struct os_mbuf *buf;
 
 	__ASSERT_NO_MSG(sub != NULL);
 
@@ -420,7 +421,10 @@ static struct os_mbuf *encode_update(struct bt_mesh_friend *frnd, u8_t md)
 	upd->iv_index = sys_cpu_to_be32(bt_mesh.iv_index);
 	upd->md = md;
 
-	return encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_UPDATE, sdu);
+	buf = encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_UPDATE, sdu);
+
+	os_mbuf_free_chain(sdu);
+	return buf;
 }
 
 static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact)
@@ -449,6 +453,7 @@ static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact)
 
 	frnd->last = buf;
 	frnd->send_last = 1;
+	os_mbuf_free_chain(sdu);
 }
 
 static void friend_recv_delay(struct bt_mesh_friend *frnd)
@@ -755,6 +760,7 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi)
 
 	frnd->last = buf;
 	frnd->send_last = 1;
+	os_mbuf_free_chain(sdu);
 }
 
 #define RECV_WIN                  CONFIG_BT_MESH_FRIEND_RECV_WIN
diff --git a/nimble/host/mesh/src/shell.c b/nimble/host/mesh/src/shell.c
index bce94a8e..25ad8c65 100644
--- a/nimble/host/mesh/src/shell.c
+++ b/nimble/host/mesh/src/shell.c
@@ -751,16 +751,17 @@ static int cmd_net_send(int argc, char *argv[])
 		.sub = bt_mesh_subnet_get(net.net_idx),
 	};
 	size_t len;
-	int err;
+	int err = 0;
 
 	if (argc < 2) {
-		return -EINVAL;
+		err = -EINVAL;
+		goto done;
 	}
 
 	if (!tx.sub) {
 		printk("No matching subnet for NetKey Index 0x%04x\n",
 		       net.net_idx);
-		return 0;
+		goto done;
 	}
 
 	net_buf_simple_init(msg, 0);
@@ -772,7 +773,9 @@ static int cmd_net_send(int argc, char *argv[])
 		printk("Failed to send (err %d)\n", err);
 	}
 
-	return 0;
+done:
+	os_mbuf_free_chain(msg);
+	return err;
 }
 
 struct shell_cmd_help cmd_net_send_help = {
@@ -909,9 +912,9 @@ struct shell_cmd_help cmd_timeout_help = {
 
 static int cmd_get_comp(int argc, char *argv[])
 {
-	struct os_mbuf*comp = NET_BUF_SIMPLE(32);
+	struct os_mbuf *comp = NET_BUF_SIMPLE(32);
 	u8_t status, page = 0x00;
-	int err;
+	int err = 0;
 
 	if (argc > 1) {
 		page = strtol(argv[1], NULL, 0);
@@ -922,12 +925,12 @@ static int cmd_get_comp(int argc, char *argv[])
 					&status, comp);
 	if (err) {
 		printk("Getting composition failed (err %d)\n", err);
-		return 0;
+		goto done;
 	}
 
 	if (status != 0x00) {
 		printk("Got non-success status 0x%02x\n", status);
-		return 0;
+		goto done;
 	}
 
 	printk("Got Composition Data for 0x%04x:\n", net.dst);
@@ -979,7 +982,9 @@ static int cmd_get_comp(int argc, char *argv[])
 		}
 	}
 
-	return 0;
+done:
+	os_mbuf_free_chain(comp);
+	return err;
 }
 
 struct shell_cmd_help cmd_get_comp_help = {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services