diff options
Diffstat (limited to 'test/Analysis/malloc.cpp')
-rw-r--r-- | test/Analysis/malloc.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/test/Analysis/malloc.cpp b/test/Analysis/malloc.cpp index 220d746..54efa1c 100644 --- a/test/Analysis/malloc.cpp +++ b/test/Analysis/malloc.cpp @@ -5,11 +5,11 @@ void *malloc(size_t); void free(void *); void *realloc(void *ptr, size_t size); void *calloc(size_t nmemb, size_t size); - +char *strdup(const char *s); void checkThatMallocCheckerIsRunning() { - malloc(4); // expected-warning{{leak}} -} + malloc(4); +} // expected-warning{{leak}} // Test for radar://11110132. struct Foo { @@ -60,3 +60,43 @@ namespace PR13751 { } } +struct X { void *a; }; + +struct X get() { + struct X result; + result.a = malloc(4); + return result; // no-warning +} + +// Ensure that regions accessible through a LazyCompoundVal trigger region escape. +// Malloc checker used to report leaks for the following two test cases. +struct Property { + char* getterName; + Property(char* n) + : getterName(n) {} + +}; +void append(Property x); + +void appendWrapper(char *getterName) { + append(Property(getterName)); +} +void foo(const char* name) { + char* getterName = strdup(name); + appendWrapper(getterName); // no-warning +} + +struct NestedProperty { + Property prop; + NestedProperty(Property p) + : prop(p) {} +}; +void appendNested(NestedProperty x); + +void appendWrapperNested(char *getterName) { + appendNested(NestedProperty(Property(getterName))); +} +void fooNested(const char* name) { + char* getterName = strdup(name); + appendWrapperNested(getterName); // no-warning +}
\ No newline at end of file |