From b75f6738019e834629e2f10fccc8dc866bf3b7c6 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 22 Apr 2014 15:41:36 +0200 Subject: [PATCH] RDC phase optimization: correct the behavior in case of memory allocation failure phase_wait did not check whether queuebuf_new_from_packetbuf() returns NULL. This potentially causes send_packet to behave incorrectly; the proper packet would not be sent out (because queuebuf_to_packetbuf(NULL) is a no-op). Instead, whatever has been left in the packet buffer by its previous user will be sent out. --- core/net/mac/phase.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/net/mac/phase.c b/core/net/mac/phase.c index ff20ae978..47b7e7cf3 100644 --- a/core/net/mac/phase.c +++ b/core/net/mac/phase.c @@ -219,6 +219,11 @@ phase_wait(const linkaddr_t *neighbor, rtimer_clock_t cycle_time, if(buf_list == NULL) { packetbuf_set_attr(PACKETBUF_ATTR_IS_CREATED_AND_SECURED, 1); p->q = queuebuf_new_from_packetbuf(); + if(p->q == NULL) { + /* memory allocation failed */ + memb_free(&queued_packets_memb, p); + return PHASE_UNKNOWN; + } } p->mac_callback = mac_callback; p->mac_callback_ptr = mac_callback_ptr;