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