You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/12/18 21:57:16 UTC

[48/50] incubator-mynewt-core git commit: oic; free incoming mbuf right after copying the data to oc_message, as opposed to after calling coap_receive().

oic; free incoming mbuf right after copying the data to oc_message,
as opposed to after calling coap_receive().


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/ed6020f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ed6020f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ed6020f6

Branch: refs/heads/sensors_branch
Commit: ed6020f68c9495f5a83b36869ab8c3dc91453295
Parents: 50ab14b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 14 10:02:42 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Sun Dec 18 13:56:17 2016 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_buffer.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed6020f6/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index 3e3cf8f..a2a00a8 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -81,6 +81,7 @@ void
 oc_message_unref(oc_message_t *message)
 {
     if (message) {
+        assert(message->ref_count > 0);
         message->ref_count--;
         if (message->ref_count == 0) {
             os_memblock_put(&oc_buffers, message);
@@ -171,6 +172,8 @@ oc_buffer_rx(struct os_event *ev)
         }
         memcpy(&msg->endpoint, OC_MBUF_ENDPOINT(m), sizeof(msg->endpoint));
         msg->length = OS_MBUF_PKTHDR(m)->omp_len;
+        os_mbuf_free_chain(m);
+        m = NULL;
 
 #ifdef OC_SECURITY
         b = m->om_data[0];
@@ -179,17 +182,17 @@ oc_buffer_rx(struct os_event *ev)
             oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], m);
         } else {
             coap_receive(msg);
-            oc_message_unref(msg);
         }
 #else
         coap_receive(msg);
-        oc_message_unref(msg);
 #endif
 free_msg:
-        os_mbuf_free_chain(m);
         if (msg) {
             oc_message_unref(msg);
         }
+        if (m) {
+            os_mbuf_free_chain(m);
+        }
     }
 }