Skip to content

Document realloc/free being not interrupt safe #6428

Closed
@devyte

Description

@devyte

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

All

Settings in IDE

All

Problem Description

With #6274, several critical section flaws were uncovered. Among them is the fact that it is not safe to use realloc() or free() from within an ISR, except maybe under very specific conditions.

At this time, there doesn't appear to be a way to make them safe, so the recommendation is: don't use them in an ISR, unless you know very well what you're doing.
"Don't use them" includes adding elements to mem-managed objects with contiguous memory, such as String, std::string and std::vector, as well as any user-implemented objects that could internally manage an array or similar.

I think use of malloc is ok from an ISR. Therefore, adding elements to mem-managed objects with non-contiguous memory should be ok, e. g. std::list, std::forward_list, std::map, etc.

Use of malloc et al from ISRs or signal handlers is not supported even in full OSs like Linux (malloc is thread safe but not interrupt safe), so this non-safety shouldn't be news to programmers. Even so, the above needs to be documented for full clarity. This issue is meant to track that.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions