summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorotto <>2018-01-28 13:38:00 +0000
committerotto <>2018-01-28 13:38:00 +0000
commit61b1ba1dd4145a63b5348c8754eca8b7aead54d1 (patch)
tree78592dd6fe79817838b5f085db92d2dbeaf78365
parent10dfde59e8d07a40881ee15f9402c6012597422e (diff)
downloadopenbsd-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/Makefile13
-rw-r--r--src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c58
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
5REGRESS_TARGETS= t1
6PROG= malloc_threaderr
7LDADD+= -pthread
8DPADD+= ${LIBPTHREAD}
9
10.include <bsd.regress.mk>
11
12t1: 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
22pthread_cond_t cond;
23pthread_mutex_t mutex;
24
25void *p;
26
27void *m(void *arg)
28{
29 p = malloc(100000);
30 if (p == NULL)
31 err(1, NULL);
32 return NULL;
33}
34
35void *f(void *arg)
36{
37 free(p);
38 free(p);
39 return NULL;
40}
41
42int
43main(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}