I have a program which forks child processes, but never invokes any exec
-style function. This is by design. The problem is that the address sanitizer does not report anything it finds (even when issues are obvious) when the child terminates via _exit()
.
As I understand it, calling _exit
or _Exit
is the correct way to end a child process which never invokes exec
. If I change the logic for the child to use return
or exit
, ASan is able to report all issues found in the child process.
Is there a way to make ASan report what it finds when _exit
is used?
Is this behavior expected?
Below is the example code I've been using to test this:
// file: main.cpp
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
const auto pid = fork();
if (pid > 0) {
std::cout << "parent: " << getpid() << '\n';
int status;
wait(&status);
}
else if (pid == 0) {
std::cout << "child: " << getpid() << '\n';
auto* p = new int;
p = nullptr;
_exit(0); // No ASan output.
//_Exit(0); // No ASan output.
//exit(0); // ASan reports leaks.
}
else {
std::perror("fork");
}
return 0;
}
Godbolt link: https://gcc.godbolt.org/z/dfsaTc7rz
- Platform: Ubuntu 20.04
- Compiler: Clang 13.0.0 (compiled from source)
Here is the command used to compile the code:
clang++ -std=c++20 -g -O0 -fsanitize=address -fno-omit-frame-pointer main.cpp
I haven't found anything in the ASan documentation that points to a solution for this.