summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Fuzzer/FuzzerLoop.cpp1
-rw-r--r--llvm/lib/Fuzzer/test/CMakeLists.txt1
-rw-r--r--llvm/lib/Fuzzer/test/LeakTest.cpp11
-rw-r--r--llvm/lib/Fuzzer/test/fuzzer.test3
4 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp
index 56c9c05fceb..7dc48e63641 100644
--- a/llvm/lib/Fuzzer/FuzzerLoop.cpp
+++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp
@@ -75,6 +75,7 @@ void Fuzzer::StaticDeathCallback() {
}
void Fuzzer::DeathCallback() {
+ if (!CurrentUnitSize) return;
Printf("DEATH:\n");
if (CurrentUnitSize <= kMaxUnitSizeToPrint) {
PrintHexArray(CurrentUnitData, CurrentUnitSize, "\n");
diff --git a/llvm/lib/Fuzzer/test/CMakeLists.txt b/llvm/lib/Fuzzer/test/CMakeLists.txt
index 3533d3b2a41..c9ccf9b565e 100644
--- a/llvm/lib/Fuzzer/test/CMakeLists.txt
+++ b/llvm/lib/Fuzzer/test/CMakeLists.txt
@@ -20,6 +20,7 @@ set(Tests
FullCoverageSetTest
InitializeTest
MemcmpTest
+ LeakTest
NullDerefTest
RepeatedMemcmp
SimpleCmpTest
diff --git a/llvm/lib/Fuzzer/test/LeakTest.cpp b/llvm/lib/Fuzzer/test/LeakTest.cpp
new file mode 100644
index 00000000000..7d153e45691
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/LeakTest.cpp
@@ -0,0 +1,11 @@
+// Test with a leak.
+#include <cstdint>
+#include <cstddef>
+
+static volatile void *Sink;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ Sink = new int;
+ return 0;
+}
+
diff --git a/llvm/lib/Fuzzer/test/fuzzer.test b/llvm/lib/Fuzzer/test/fuzzer.test
index 3a617784b95..d826fd72567 100644
--- a/llvm/lib/Fuzzer/test/fuzzer.test
+++ b/llvm/lib/Fuzzer/test/fuzzer.test
@@ -57,3 +57,6 @@ SINGLE_INPUTS: LLVMFuzzer-SimpleTest: Running 2 inputs.
SINGLE_INPUTS: aaa:
SINGLE_INPUTS: bbb:
+RUN: LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK
+LEAK: ERROR: LeakSanitizer: detected memory leaks
+LEAK-NOT: DEATH:
OpenPOWER on IntegriCloud