2 #include "analyzer-decls.h"
6 static int __attribute__((noinline
))
7 do_stuff_2 (int *p
, int n
)
12 /* As malloc-vs-local-2.c, but with a memory leak for the "on the heap case"
13 by not attempting to free at the end. */
22 ptr
= (int *)malloc (sizeof (int) * n
);
26 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
32 for (i
= 0; i
< n
; i
++)
33 p
[i
] = i
; /* { dg-warning "dereference of possibly-NULL" } */
34 for (i
= 0; i
< n
; i
++)
35 sum
+= foo (p
[i
]); /* { dg-bogus "uninitialized" } */
39 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
41 return result
; /* { dg-message "leak of 'p'|leak of 'ptr'" } */
44 /* A simpler version of the above. */
53 ptr
= (int *)malloc (sizeof (int) * n
);
57 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
59 result
= do_stuff_2 (ptr
, n
);
61 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
63 return result
; /* { dg-message "leak of 'ptr'" } */