Skip to content

Memory allocation is not safe between fork() and execve() #549

@madmaxoft

Description

@madmaxoft

According to POSIX, memory allocation using malloc (and thus new inherently as well) is not a safe operation after a fork call, because libc may have been allocating memory in another thread and so could have some mutexes locked, which would deadlock the child.

See this article for a nice explanation:
http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them

Unfortunately Poco::Process::launch() implementation does allocate memory at least in two places I've seen so far:
https://github.com/pocoproject/poco/blob/develop/Foundation/src/Process_UNIX.cpp#L184
https://github.com/pocoproject/poco/blob/develop/Foundation/src/Environment_UNIX.cpp#L63-L65
(called from https://github.com/pocoproject/poco/blob/develop/Foundation/src/Process_UNIX.cpp#L167 )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions