Skip to content

Commit b86e1d0

Browse files
[libc][test] fix memory leak pt.2
These were created with operator new (see `Test::createCallable`), so operator delete should be used instead of free(). Fixes: llvm#122369 Fixes: llvm#122378
1 parent 3caa68a commit b86e1d0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

libc/test/UnitTest/ExecuteFunctionUnix.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int ProcessStatus::get_fatal_signal() {
3737
ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
3838
int pipe_fds[2];
3939
if (::pipe(pipe_fds) == -1) {
40-
::free(func);
40+
delete func;
4141
return ProcessStatus::error("pipe(2) failed");
4242
}
4343

@@ -46,13 +46,13 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
4646
::fflush(stdout);
4747
pid_t pid = ::fork();
4848
if (pid == -1) {
49-
::free(func);
49+
delete func;
5050
return ProcessStatus::error("fork(2) failed");
5151
}
5252

5353
if (!pid) {
5454
(*func)();
55-
::free(func);
55+
delete func;
5656
::exit(0);
5757
}
5858
::close(pipe_fds[1]);
@@ -63,13 +63,13 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
6363
// No events requested so this call will only return after the timeout or if
6464
// the pipes peer was closed, signaling the process exited.
6565
if (::poll(&poll_fd, 1, timeout_ms) == -1) {
66-
::free(func);
66+
delete func;
6767
return ProcessStatus::error("poll(2) failed");
6868
}
6969
// If the pipe wasn't closed by the child yet then timeout has expired.
7070
if (!(poll_fd.revents & POLLHUP)) {
7171
::kill(pid, SIGKILL);
72-
::free(func);
72+
delete func;
7373
return ProcessStatus::timed_out_ps();
7474
}
7575

@@ -78,11 +78,11 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
7878
// and doesn't turn into a zombie.
7979
pid_t status = ::waitpid(pid, &wstatus, 0);
8080
if (status == -1) {
81-
::free(func);
81+
delete func;
8282
return ProcessStatus::error("waitpid(2) failed");
8383
}
8484
assert(status == pid);
85-
::free(func);
85+
delete func;
8686
return {wstatus};
8787
}
8888

libc/test/UnitTest/FPExceptMatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) {
4444
fputil::get_env(&oldEnv);
4545
if (sigsetjmp(jumpBuffer, 1) == 0)
4646
func->call();
47-
free(func);
47+
delete func;
4848
// We restore the previous floating point environment after
4949
// the call to the function which can potentially raise SIGFPE.
5050
fputil::set_env(&oldEnv);

0 commit comments

Comments
 (0)