aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/malloc.c
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-02-23 01:05:27 +0000
committerAnna Zaks <ganna@apple.com>2012-02-23 01:05:27 +0000
commit0d389b819c33bdf0375694a8f141c8f02e002b18 (patch)
treeb0dad024f79fb9fc3289175afba2449a9b7daec5 /test/Analysis/malloc.c
parenta5964421cf9ce56a3cda57c5902d104d800a2a9e (diff)
[analyzer] Invalidate the region passed to pthread_setspecific() call.
Make this call an exception in ExprEngine::invalidateArguments: 'int pthread_setspecific(ptheread_key k, const void *)' stores a value into thread local storage. The value can later be retrieved with 'void *ptheread_getspecific(pthread_key)'. So even thought the parameter is 'const void *', the region escapes through the call. (Here we just blacklist the call in the ExprEngine's default logic. Another option would be to add a checker which evaluates the call and triggers the call to invalidate regions.) Teach the Malloc Checker, which treats all system calls as safe about the API. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151220 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r--test/Analysis/malloc.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c
index 1923305fe2..4e42657c19 100644
--- a/test/Analysis/malloc.c
+++ b/test/Analysis/malloc.c
@@ -677,6 +677,16 @@ void testStrdupContentIsDefined(const char *s, unsigned validIndex) {
free(s2);
}
+// Test the system library functions to which the pointer can escape.
+
+// For now, we assume memory passed to pthread_specific escapes.
+// TODO: We could check that if a new pthread binding is set, the existing
+// binding must be freed; otherwise, a memory leak can occur.
+void testPthereadSpecificEscape(pthread_key_t key) {
+ void *buf = malloc(12);
+ pthread_setspecific(key, buf); // no warning
+}
+
// Below are the known false positives.
// TODO: There should be no warning here. This one might be difficult to get rid of.