diff options
Diffstat (limited to 'test/Analysis/new.cpp')
-rw-r--r-- | test/Analysis/new.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/Analysis/new.cpp b/test/Analysis/new.cpp index 44ae980..8d3eee9 100644 --- a/test/Analysis/new.cpp +++ b/test/Analysis/new.cpp @@ -8,6 +8,12 @@ extern "C" void *malloc(size_t); extern "C" void free(void *); int someGlobal; + +class SomeClass { +public: + void f(int *p); +}; + void testImplicitlyDeclaredGlobalNew() { if (someGlobal != 0) return; @@ -101,6 +107,12 @@ void testCacheOut(PtrWrapper w) { new (&w.x) (int*)(0); // we cache out here; don't crash } +void testUseAfter(int *p) { + SomeClass *c = new SomeClass; + free(p); + c->f(p); // expected-warning{{Use of memory after it is freed}} + delete c; +} //-------------------------------------------------------------------- // Check for intersection with other checkers from MallocChecker.cpp @@ -126,7 +138,7 @@ void testNewDeleteNoWarn() { void testDeleteMallocked() { int *x = (int *)malloc(sizeof(int)); delete x; // FIXME: Shoud detect pointer escape and keep silent after 'delete' is modeled properly. -} // expected-warning{{Memory is never released; potential leak}} +} // expected-warning{{Potential leak of memory pointed to by 'x'}} void testDeleteOpAfterFree() { int *p = (int *)malloc(sizeof(int)); @@ -152,6 +164,12 @@ void testCustomPlacementNewAfterFree() { p = new(0, p) int; // expected-warning{{Use of memory after it is freed}} } +void testUsingThisAfterDelete() { + SomeClass *c = new SomeClass; + delete c; + c->f(0); // no-warning +} + //-------------------------------- // Incorrectly-modelled behavior //-------------------------------- |