File: xml1.c

package info (click to toggle)
valgrind 1%3A3.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 176,332 kB
  • sloc: ansic: 795,029; exp: 26,134; xml: 23,472; asm: 14,393; cpp: 9,397; makefile: 7,464; sh: 6,122; perl: 5,446; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (69 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

#include <stdlib.h>
#include <stdio.h>

static void* return_arg(void* p);
int frame3 ( void )
{
  int *a = malloc(10 * sizeof(int));

  // bad address;
  int n = a[10];

  // undefined condition
  if (a[5] == 42) {
    printf("hello from frame3().  The answer is 42.\n");
  } else {
    printf("hello from frame3().  The answer is not 42.\n");
  }

  // undefined address (careful ..)
  n = a[  a[0] & 7  ];

  // invalid free, the second time
  free(a);
  free(a);

  // more invalid frees
  free(return_arg(&n));

  // leak ..
  a = malloc(99 * sizeof(int));

  // pass garbage to the exit syscall
  return n;
}

int frame2 ( void )
{
  return frame3() - 1;
}

int frame1 ( void )
{
  return frame2() + 1;
}

int main ( void )
{
  int ret = frame1() - 1;

#if defined(VGO_solaris)
  /* Avoid reporting possible memory leak on finish when both FILE->base
     and FILE->ptr point to the middle of a buffer allocated in _findbuf()
     for stdout. */
  fcloseall();
#endif
  return ret;
}

/*
 * The only purpose of the function below is to make sure that gcc 4.4.x does
 * not print the following warning during the compilation of this test program:
 * warning: attempt to free a non-heap object
 */
static void* return_arg(void* p)
{
   return p;
}