Skip to content

Commit 743554d

Browse files
authored
Merge pull request #58 from stefano-p/fix/tau_realloc
Fix critical bug in tau_realloc causing memory leaks and undefined behavior
2 parents 9a6f88f + 936de85 commit 743554d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tau/tau.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,13 @@ static void tauClockPrintDuration(const double nanoseconds_duration) {
319319

320320
static inline void* tau_realloc(void* const ptr, const tau_ull new_size) {
321321
void* const new_ptr = realloc(ptr, new_size);
322-
323-
if(TAU_NONE(new_ptr))
324-
free(new_ptr);
325-
322+
323+
if(TAU_NONE(new_ptr) && new_size > 0) {
324+
fprintf(stderr, "FATAL: tau_realloc failed to allocate %" TAU_PRIu64 " bytes\n",
325+
(tau_u64)new_size);
326+
TAU_ABORT;
327+
}
328+
326329
return new_ptr;
327330
}
328331
#endif // TAU_NO_TESTING

0 commit comments

Comments
 (0)