Skip to content

Commit 980338c

Browse files
Deallocate memory in case of failure rather than waiting for next invocation of the profiler
1 parent dc69cf4 commit 980338c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/profiler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ Error Profiler::start(Arguments& args, bool reset) {
902902
free(_calltrace_buffer[i]);
903903
_calltrace_buffer[i] = (CallTraceBuffer*)calloc(nelem, sizeof(CallTraceBuffer));
904904
if (_calltrace_buffer[i] == NULL) {
905+
for (int j = i - 1; j >= 0; j--) {
906+
free(_calltrace_buffer[i]);
907+
_calltrace_buffer[i] = NULL;
908+
}
905909
_max_stack_depth = 0;
906910
return Error("Not enough memory to allocate stack trace buffers (try smaller jstackdepth)");
907911
}

0 commit comments

Comments
 (0)