1 #include <string.h>
2 #include <stdlib.h>
3 
4 extern void requires_nonnull (void *ptr)
5   __attribute__((nonnull));
6 
test_1(const char * s)7 void test_1 (const char *s)
8 {
9   char *p = strdup (s); /* { dg-message "allocated here" } */
10 } /* { dg-warning "leak of 'p'" } */
11 
test_2(const char * s)12 void test_2 (const char *s)
13 {
14   char *p = strdup (s);
15   free (p);
16 }
test_3(const char * s)17 void test_3 (const char *s)
18 {
19   char *p = strdup (s); /* { dg-message "this call could return NULL" } */
20   requires_nonnull (p); /* { dg-warning "use of possibly-NULL 'p'" } */
21 }
22