Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce safety checks on heap usage from ISRs #1761

merged 3 commits into from May 16, 2019


Copy link

commented Apr 30, 2019


Apparently we don't have checks on whether malloc()/free() etc functions are being called from an ISR, which should not be possible due to the usage of a semaphore for thread-safety.

We did have assertions for this previously but only for Electron.


This PR renames SemaphoreLockTimeout panic code into a generic HeapError and adds HAL_IsISR() checks to malloc(), free(), realloc(), mallinfo(), and malloc_usable_size() functions (instead of __malloc_lock()/unlock() which are implemented separately for each platform and defined in WICED for Photons and P1 for example).

Steps to Test

Run the example app, the device should panic once D0 is deasserted.

Example App

void setup() {
    pinMode(D0, INPUT_PULLUP);
    attachInterrupt(D0, (wiring_interrupt_handler_t)[](void) -> void {
        void* ptr = malloc(1024);
    }, FALLING);


  • [CH31998]


  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to after merging (add links to docs and issues)

  • [enhancement] Introduce safety checks on heap usage from ISRs #1761

@avtolstoy avtolstoy added this to the 1.2.0-beta.2 milestone Apr 30, 2019

@avtolstoy avtolstoy requested a review from sergeuz Apr 30, 2019

@avtolstoy avtolstoy requested a review from sergeuz Apr 30, 2019

@avtolstoy avtolstoy removed the do not merge label Apr 30, 2019

@avtolstoy avtolstoy requested a review from technobly Apr 30, 2019

@technobly technobly modified the milestones: 1.2.0-beta.2, 1.2.0-rc.1 May 10, 2019

@avtolstoy avtolstoy force-pushed the feature/assert-heap-usage-in-isr branch from 89657d8 to 02503cb May 16, 2019

@avtolstoy avtolstoy merged commit 525aba5 into develop May 16, 2019

1 check passed

continuous-integration/travis-ci/push The Travis CI build passed

@avtolstoy avtolstoy deleted the feature/assert-heap-usage-in-isr branch May 16, 2019

@technobly technobly removed the request for review from sergeuz May 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.