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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include "config.h"
#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#if defined(HAVE_SYS_PRCTL_H)
#include <sys/prctl.h>
#endif /* HAVE_SYS_PRCTL_H */
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>
#include "valgrind.h"
static pthread_t children[3];
void bad_things(int offset)
{
char* m = malloc(sizeof(char)*offset);
m[offset] = 0;
free(m);
}
void* child_fn_2 ( void* arg )
{
const char* threadname = "012345678901234";
# if !defined(VGO_darwin)
pthread_setname_np(pthread_self(), threadname);
# else
pthread_setname_np(threadname);
# endif
bad_things(4);
return NULL;
}
void* child_fn_1 ( void* arg )
{
const char* threadname = "try1";
int r;
# if !defined(VGO_darwin)
pthread_setname_np(pthread_self(), threadname);
# else
pthread_setname_np(threadname);
# endif
bad_things(3);
VALGRIND_PRINTF("%s", "I am in child_fn_1\n");
r = pthread_create(&children[2], NULL, child_fn_2, NULL);
assert(!r);
r = pthread_join(children[2], NULL);
assert(!r);
return NULL;
}
void* child_fn_0 ( void* arg )
{
int r;
bad_things(2);
r = pthread_create(&children[1], NULL, child_fn_1, NULL);
assert(!r);
r = pthread_join(children[1], NULL);
assert(!r);
return NULL;
}
int main(int argc, const char** argv)
{
int r;
bad_things(1);
r = pthread_create(&children[0], NULL, child_fn_0, NULL);
assert(!r);
r = pthread_join(children[0], NULL);
assert(!r);
bad_things(5);
return 0;
}
|