Realloc() is not wrapped for multi-core safety #863

Closed
opened 2022-06-12 15:13:29 -05:00 by earlephilhower · 1 comment
earlephilhower commented 2022-06-12 15:13:29 -05:00 (Migrated from github.com)

[Sorry about busted issue before, I hit return by accident instead of tab]

In pico_malloc.c we wrap malloc, free, and calloc to protect the heap in the case of multicore operation.

The standard C function realloc is, however, unwrapped. This can lead to very interesting crashes due to heap corruption if both cores run memory code at the same time (https://github.com/maxgerhardt/platform-raspberrypi/issues/7).

I'll submit a PR fixing this later today, but wanted to track it with an issue in case someone else runs into the same thing I did. We had some code which only failed under very specific timing circumstances and the two cores only exactly aligned and hit it with a particular GCC -O level.

[Sorry about busted issue before, I hit return by accident instead of tab] In `pico_malloc.c` we wrap `malloc`, `free`, and `calloc` to protect the heap in the case of multicore operation. The standard C function `realloc` is, however, unwrapped. This can lead to very interesting crashes due to heap corruption if both cores run memory code at the same time (https://github.com/maxgerhardt/platform-raspberrypi/issues/7). I'll submit a PR fixing this later today, but wanted to track it with an issue in case someone else runs into the same thing I did. We had some code which only failed under very specific timing circumstances and the two cores only exactly aligned and hit it with a particular GCC `-O` level.
earlephilhower commented 2022-06-24 04:41:07 -05:00 (Migrated from github.com)

Closing as this fix was merged into develop.

Closing as this fix was merged into develop.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#863
No description provided.