[libFuzzer] don't report memory leaks if we are dying due to a timeout (just use _Exit instead of exit in the timeout callback)

llvm-svn: 264237
This commit is contained in:
Kostya Serebryany 2016-03-24 01:32:08 +00:00
parent 37df19ebee
commit 315167339e
5 changed files with 25 additions and 5 deletions

View File

@ -164,7 +164,7 @@ void Fuzzer::AlarmCallback() {
__sanitizer_print_stack_trace();
Printf("SUMMARY: libFuzzer: timeout\n");
PrintFinalStats();
exit(Options.TimeoutExitCode);
_Exit(Options.TimeoutExitCode); // Stop right now.
}
}

View File

@ -22,6 +22,7 @@ set(Tests
InitializeTest
MemcmpTest
LeakTest
LeakTimeoutTest
NullDerefTest
NthRunCrashTest
RepeatedMemcmp

View File

@ -0,0 +1,14 @@
// Test with a leak.
#include <cstdint>
#include <cstddef>
static volatile int *Sink;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
if (!Size) return 0;
Sink = new int;
Sink = new int;
while (Sink) *Sink = 0; // Infinite loop.
return 0;
}

View File

@ -0,0 +1,9 @@
RUN: not LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK
LEAK: ERROR: LeakSanitizer: detected memory leaks
LEAK-NOT: DEATH:
RUN: not LLVMFuzzer-LeakTimeoutTest -timeout=1 2>&1 | FileCheck %s --check-prefix=LEAK_TIMEOUT
LEAK_TIMEOUT: ERROR: libFuzzer: timeout after
LEAK_TIMEOUT-NOT: LeakSanitizer

View File

@ -69,10 +69,6 @@ RUN: LLVMFuzzer-SimpleTest %t/SUB1 -runs=0 2>&1 | FileCheck %s --check-prefix=SU
SUBDIRS: READ units: 3
RUN: rm -rf %t/SUB1
RUN: not LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK
LEAK: ERROR: LeakSanitizer: detected memory leaks
LEAK-NOT: DEATH:
RUN: mkdir -p %t
RUN: echo abcd > %t/NthRunCrashTest.in
RUN: LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in