-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[libc][test] fix memory leak #122378
[libc][test] fix memory leak #122378
Conversation
Looks like the smart pointer I removed was being used to free the underlying object. Fixes: llvm#122369
@llvm/pr-subscribers-libc Author: Nick Desaulniers (nickdesaulniers) ChangesLooks like the smart pointer I removed was being used to free the underlying Fixes: #122369 Full diff: https://github.com/llvm/llvm-project/pull/122378.diff 2 Files Affected:
diff --git a/libc/test/UnitTest/ExecuteFunctionUnix.cpp b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
index df71738668592a..b004e8c0891171 100644
--- a/libc/test/UnitTest/ExecuteFunctionUnix.cpp
+++ b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
@@ -36,18 +36,23 @@ int ProcessStatus::get_fatal_signal() {
ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
int pipe_fds[2];
- if (::pipe(pipe_fds) == -1)
+ if (::pipe(pipe_fds) == -1) {
+ ::free(func);
return ProcessStatus::error("pipe(2) failed");
+ }
// Don't copy the buffers into the child process and print twice.
::fflush(stderr);
::fflush(stdout);
pid_t pid = ::fork();
- if (pid == -1)
+ if (pid == -1) {
+ ::free(func);
return ProcessStatus::error("fork(2) failed");
+ }
if (!pid) {
(*func)();
+ ::free(func);
::exit(0);
}
::close(pipe_fds[1]);
@@ -57,11 +62,14 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
};
// No events requested so this call will only return after the timeout or if
// the pipes peer was closed, signaling the process exited.
- if (::poll(&poll_fd, 1, timeout_ms) == -1)
+ if (::poll(&poll_fd, 1, timeout_ms) == -1) {
+ ::free(func);
return ProcessStatus::error("poll(2) failed");
+ }
// If the pipe wasn't closed by the child yet then timeout has expired.
if (!(poll_fd.revents & POLLHUP)) {
::kill(pid, SIGKILL);
+ ::free(func);
return ProcessStatus::timed_out_ps();
}
@@ -69,9 +77,12 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
// Wait on the pid of the subprocess here so it gets collected by the system
// and doesn't turn into a zombie.
pid_t status = ::waitpid(pid, &wstatus, 0);
- if (status == -1)
+ if (status == -1) {
+ ::free(func);
return ProcessStatus::error("waitpid(2) failed");
+ }
assert(status == pid);
+ ::free(func);
return {wstatus};
}
diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index 889f9f6f44a913..928c3df6ac48a6 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -44,6 +44,7 @@ FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) {
fputil::get_env(&oldEnv);
if (sigsetjmp(jumpBuffer, 1) == 0)
func->call();
+ free(func);
// We restore the previous floating point environment after
// the call to the function which can potentially raise SIGFPE.
fputil::set_env(&oldEnv);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have some sort of RAII wrapper that could handle this? Seems a little cumbersome to track each branch.
No; it's probably not too bad to add a |
still fails: https://lab.llvm.org/buildbot/#/builders/171/builds/13529. Hmm...did I miss something? |
oh, do I need |
These were created with operator new (see `Test::createCallable`), so operator delete should be used instead of free(). Fixes: llvm#122369 Fixes: llvm#122378
Looks like the smart pointer I removed was being used to free the underlying object. Fixes: llvm#122369
These were created with operator new (see `Test::createCallable`), so operator delete should be used instead of free(). Fixes: llvm#122369 Fixes: llvm#122378
Looks like the smart pointer I removed was being used to free the underlying object. Fixes: llvm#122369
These were created with operator new (see `Test::createCallable`), so operator delete should be used instead of free(). Fixes: llvm#122369 Fixes: llvm#122378
Looks like the smart pointer I removed was being used to free the underlying object. Fixes: llvm#122369
These were created with operator new (see `Test::createCallable`), so operator delete should be used instead of free(). Fixes: llvm#122369 Fixes: llvm#122378
Looks like the smart pointer I removed was being used to free the underlying
object.
Fixes: #122369