forked from OSchip/llvm-project
[lsan][test] Add malloc(0) and realloc(p, 0) tests
This commit is contained in:
parent
9b0517035f
commit
59e422c90b
|
@ -0,0 +1,15 @@
|
|||
// RUN: %clang_lsan %s -o %t
|
||||
// RUN: %env_lsan_opts=use_stacks=0 not %run %t 2>&1 | FileCheck %s
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// CHECK: {{Leak|Address}}Sanitizer: detected memory leaks
|
||||
// CHECK: {{Leak|Address}}Sanitizer: 1 byte(s) leaked in 1 allocation(s).
|
||||
|
||||
int main() {
|
||||
// The behavior of malloc(0) is implementation-defined.
|
||||
char *p = malloc(0);
|
||||
fprintf(stderr, "zero: %p\n", p);
|
||||
p = 0;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
// RUN: %clang_lsan %s -o %t
|
||||
// RUN: %run %t
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
char *p = malloc(1);
|
||||
// The behavior of realloc(p, 0) is implementation-defined.
|
||||
// We free the allocation.
|
||||
assert(realloc(p, 0) == NULL);
|
||||
p = 0;
|
||||
}
|
Loading…
Reference in New Issue