1 /* 2 * Copyright (c) 2018 Otto Moerbeek <otto@drijf.net> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <err.h> 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <pthread.h> 21 22 pthread_cond_t cond; 23 pthread_mutex_t mutex; 24 25 void *p; 26 27 void *m(void *arg) 28 { 29 p = malloc(100000); 30 if (p == NULL) 31 err(1, NULL); 32 return NULL; 33 } 34 35 void *f(void *arg) 36 { 37 free(p); 38 free(p); 39 return NULL; 40 } 41 42 int 43 main(void) 44 { 45 pthread_t t1, t2; 46 47 printf("This test is supposed to print a malloc error and create a core dump\n"); 48 49 if (pthread_create(&t1, NULL, m, NULL)) 50 err(1, "pthread_create"); 51 pthread_join(t1, NULL); 52 53 if (pthread_create(&t2, NULL, f, NULL)) 54 err(1, "pthread_create"); 55 pthread_join(t2, NULL); 56 57 return 0; 58 } 59