diff options
author | otto <> | 2018-01-28 13:38:00 +0000 |
---|---|---|
committer | otto <> | 2018-01-28 13:38:00 +0000 |
commit | 61b1ba1dd4145a63b5348c8754eca8b7aead54d1 (patch) | |
tree | 78592dd6fe79817838b5f085db92d2dbeaf78365 | |
parent | 10dfde59e8d07a40881ee15f9402c6012597422e (diff) | |
download | openbsd-61b1ba1dd4145a63b5348c8754eca8b7aead54d1.tar.gz openbsd-61b1ba1dd4145a63b5348c8754eca8b7aead54d1.tar.bz2 openbsd-61b1ba1dd4145a63b5348c8754eca8b7aead54d1.zip |
Test for correct error when on thread allocates, and another does a double free
-rw-r--r-- | src/regress/lib/libc/malloc/malloc_threaderr/Makefile | 13 | ||||
-rw-r--r-- | src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c | 58 |
2 files changed, 71 insertions, 0 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile b/src/regress/lib/libc/malloc/malloc_threaderr/Makefile new file mode 100644 index 0000000000..ef510adbff --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_threaderr/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2018/01/28 13:38:00 otto Exp $ | ||
2 | |||
3 | # This test is supposed to print a malloc error and create a core dump | ||
4 | |||
5 | REGRESS_TARGETS= t1 | ||
6 | PROG= malloc_threaderr | ||
7 | LDADD+= -pthread | ||
8 | DPADD+= ${LIBPTHREAD} | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
11 | |||
12 | t1: malloc_threaderr | ||
13 | ${.OBJDIR}/malloc_threaderror 2>&1 | fgrep 'in free(): bogus pointer (double free?)' | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c b/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c new file mode 100644 index 0000000000..f34f37fc93 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c | |||
@@ -0,0 +1,58 @@ | |||
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 | } | ||