tests/vg_regtest: Always evaluate prerequisite expressions with sh
[valgrind.git] / memcheck / tests / xml1.c
blob0cbbb03165a468fbcb01d0573fcfc2b1fac24d7f
2 #include <stdlib.h>
3 #include <stdio.h>
5 static void* return_arg(void* p);
6 int frame3 ( void )
8 int *a = malloc(10 * sizeof(int));
10 // bad address;
11 int n = a[10];
13 // undefined condition
14 if (a[5] == 42) {
15 printf("hello from frame3(). The answer is 42.\n");
16 } else {
17 printf("hello from frame3(). The answer is not 42.\n");
20 // undefined address (careful ..)
21 n = a[ a[0] & 7 ];
23 // invalid free, the second time
24 free(a);
25 free(a);
27 // more invalid frees
28 free(return_arg(&n));
30 // leak ..
31 a = malloc(99 * sizeof(int));
33 // pass garbage to the exit syscall
34 return n;
37 int frame2 ( void )
39 return frame3() - 1;
42 int frame1 ( void )
44 return frame2() + 1;
47 int main ( void )
49 int ret = frame1() - 1;
51 #if defined(VGO_solaris)
52 /* Avoid reporting possible memory leak on finish when both FILE->base
53 and FILE->ptr point to the middle of a buffer allocated in _findbuf()
54 for stdout. */
55 fcloseall();
56 #endif
57 return ret;
61 * The only purpose of the function below is to make sure that gcc 4.4.x does
62 * not print the following warning during the compilation of this test program:
63 * warning: attempt to free a non-heap object
65 static void* return_arg(void* p)
67 return p;