BLE Host - Free mbuf on os_mqueue_put() failure.

This fixes a theoretical mbuf leak.  In practice, the call to
os_mqueue_put() will never fail.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5c65aafe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5c65aafe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5c65aafe

Branch: refs/heads/phyrx_no_mbuf
Commit: 5c65aafea8e366336e5bae303b665efef3c3d560
Parents: 5f3def8
Author: Christopher Collins <[email protected]>
Authored: Fri Aug 5 12:16:40 2016 -0700
Committer: William San Filippo <[email protected]>
Committed: Thu Aug 11 14:26:25 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c65aafe/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 225b26c..02db879 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -496,6 +496,15 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
     return rc;
 }
 
+/**
+ * Enqueues an ACL data packet for transmission.  This function consumes the
+ * supplied mbuf, regardless of the outcome.
+ *
+ * @param om                    The outgoing data packet, beginning with the
+ *                                  HCI ACL data header.
+ *
+ * @return                      0 on success; nonzero on failure.
+ */
 int
 ble_hs_tx_data(struct os_mbuf *om)
 {
@@ -503,6 +512,7 @@ ble_hs_tx_data(struct os_mbuf *om)
 
     rc = os_mqueue_put(&ble_hs_tx_q, &ble_hs_evq, om);
     if (rc != 0) {
+        os_mbuf_free_chain(om);
         return BLE_HS_EOS;
     }
     os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);

Reply via email to