Skip to content

Conversation

@purplesyringa
Copy link
Contributor

Error::new allocates memory (see rust-lang/rust#148971). This is bad in multi-threaded programs, which virtual-terminal as a library can be used in. If the fork occurs while the allocator lock is held by another thread, deadlocks can occur, since there's no one left in the new process to unlock the mutex. I do not believe this is UB, and modern libc offer protections against this issue, but this isn't POSIX-compliant and should preferably be avoided.

last_os_error does not allocate, but only supports error codes. However, the old method swallowed both the text and the error code, so hopefully that isn't a problem. If necessary, a valid approach to transmit an error would be to write to stderr (e.g. by panicking), but this is ugly.

@divi255
Copy link
Contributor

divi255 commented Nov 21, 2025

Good day,

thanks for reporting I will review and merge this soon. btw to avoid additional allocations in realtime and other similar programs, heap preallocation is also useful (see https://docs.rs/rtsc/latest/rtsc/thread_rt/fn.preallocate_heap.html)

@divi255 divi255 merged commit 25f6b9a into roboplc:main Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants