]> granicus.if.org Git - esp-idf/commitdiff
component/bt: add protection in GKI_getbuf to protect against memory allocation failure;
authorwangmengyang <wangmengyang@espressif.com>
Thu, 24 Nov 2016 16:05:39 +0000 (00:05 +0800)
committerwangmengyang <wangmengyang@espressif.com>
Thu, 24 Nov 2016 16:05:39 +0000 (00:05 +0800)
components/bt/bluedroid/gki/gki_buffer.c

index 29ac5b43e72d46b12da48a21f51f18e780d914c4..7a6031adc6d65bfa95d72ecd24104cef839a2ccc 100755 (executable)
@@ -196,12 +196,17 @@ void GKI_init_q (BUFFER_Q *p_q)
 void *GKI_getbuf (UINT16 size)
 {
   BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
-  header->status  = BUF_STATUS_UNLINKED;
-  header->p_next  = NULL;
-  header->Type    = 0;
-  header->size = size;
-
-  return header + 1;
+  assert(header != NULL);
+  if (header != NULL) {
+    header->status  = BUF_STATUS_UNLINKED;
+    header->p_next  = NULL;
+    header->Type    = 0;
+    header->size = size;
+
+    return header + 1;
+  } else {
+      return NULL;
+  }
 }