• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "config.h"
2 
3 #define _GNU_SOURCE
4 #include <stdio.h>
5 #include <pthread.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #if defined(HAVE_SYS_PRCTL_H)
9 #include <sys/prctl.h>
10 #endif /* HAVE_SYS_PRCTL_H */
11 #include <sys/types.h>
12 #include <unistd.h>
13 #include <assert.h>
14 #include "valgrind.h"
15 
16 static pthread_t children[3];
17 
bad_things(int offset)18 void bad_things(int offset)
19 {
20   char* m = malloc(sizeof(char)*offset);
21   m[offset] = 0;
22   free(m);
23 }
24 
child_fn_2(void * arg)25 void* child_fn_2 ( void* arg )
26 {
27   const char* threadname = "012345678901234";
28 
29 #  if !defined(VGO_darwin)
30   pthread_setname_np(pthread_self(), threadname);
31 #  else
32   pthread_setname_np(threadname);
33 #  endif
34 
35   bad_things(4);
36 
37   return NULL;
38 }
39 
child_fn_1(void * arg)40 void* child_fn_1 ( void* arg )
41 {
42   const char* threadname = "try1";
43   int r;
44 
45 #  if !defined(VGO_darwin)
46   pthread_setname_np(pthread_self(), threadname);
47 #  else
48   pthread_setname_np(threadname);
49 #  endif
50 
51   bad_things(3);
52   VALGRIND_PRINTF("%s", "I am in child_fn_1\n");
53 
54   r = pthread_create(&children[2], NULL, child_fn_2, NULL);
55   assert(!r);
56 
57   r = pthread_join(children[2], NULL);
58   assert(!r);
59 
60   return NULL;
61 }
62 
child_fn_0(void * arg)63 void* child_fn_0 ( void* arg )
64 {
65   int r;
66 
67   bad_things(2);
68 
69   r = pthread_create(&children[1], NULL, child_fn_1, NULL);
70   assert(!r);
71 
72   r = pthread_join(children[1], NULL);
73   assert(!r);
74 
75   return NULL;
76 }
77 
main(int argc,const char ** argv)78 int main(int argc, const char** argv)
79 {
80   int r;
81 
82   bad_things(1);
83 
84   r = pthread_create(&children[0], NULL, child_fn_0, NULL);
85   assert(!r);
86 
87   r = pthread_join(children[0], NULL);
88   assert(!r);
89 
90   bad_things(5);
91 
92   return 0;
93 }
94 
95