History

add error case to mpool_free

Matthew Wang committed 6 years ago

Commit 17acc7e1 parent 1bf02963 files · +10 −2Browse files

Unified · Split

3 files
  1. leaf/Src/leaf-mempool.c +6 −0
  2. leaf/Src/leaf.c +2 −1
  3. leaf/leaf.h +2 −1
leaf/Src/leaf-mempool.c+6−0
@@ -261,6 +261,12 @@ void mpool_free(char* ptr, _tMempool* pool) · 260 unmodified lines
261261 mpool_node_t* next_node;
262262 while (other_node != NULL)
263263 {
264+ if ((char*)other_node < (char*)pool->head ||
265+ (char*)other_node >= ((char*)pool->head + pool->msize))
266+ {
267+ LEAF_error(2);
268+ return;
269+ }
264270 next_node = other_node->next;
265271 // Check if a node is directly after the freed node
266272 if ((long) freed_node + (leaf.header_size + freed_node->size) == (long) other_node)
leaf/Src/leaf.c+2−1
@@ -54,7 +54,8 @@ float LEAF_getSampleRate() · 53 unmodified lines
5454
5555
5656 //implement a function called this in your user code to catch errors
57−__attribute__((weak)) uint8_t LEAF_error(uint8_t whichone)
57+//__attribute__((weak))
58+uint8_t LEAF_error(uint8_t whichone)
5859 {
5960 return whichone;
6061 }
leaf/leaf.h+2−1
@@ -140,7 +140,8 @@ extern "C" { · 139 unmodified lines
140140 float LEAF_getSampleRate (void);
141141
142142
143− __attribute__((weak)) uint8_t LEAF_error(uint8_t whichone);
143+// __attribute__((weak))
144+ uint8_t LEAF_error(uint8_t whichone);
144145
145146 /*!
146147 * @}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t