summaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-07-13 14:59:29 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-07-13 14:59:29 +0000
commitaf9b551b3f8f35d502a5b7e9555e37e9bab090b7 (patch)
tree1a4dbb78bdb0382bb8e5c9b6ae0295e1cd441479 /sys/kern/kern_malloc.c
parente4de52a7c544b6db1df9deabff97c027591d33f1 (diff)
if the freedsize isn't zero, check that's reasonable. ok beck
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 496775f6697..bd9db5137e9 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.113 2014/07/12 18:43:32 tedu Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.114 2014/07/13 14:59:28 tedu Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -354,7 +354,7 @@ out:
* Free a block of memory allocated by malloc.
*/
void
-free(void *addr, int type, size_t fauxsize)
+free(void *addr, int type, size_t freedsize)
{
struct kmembuckets *kbp;
struct kmemusage *kup;
@@ -387,6 +387,11 @@ free(void *addr, int type, size_t fauxsize)
kbp = &bucket[kup->ku_indx];
s = splvm();
#ifdef DIAGNOSTIC
+ if (freedsize != 0 && freedsize > size)
+ panic("freed too much: %zu > %ld (%p)", freedsize, size, addr);
+ if (freedsize != 0 && size > MINALLOCSIZE && freedsize < size / 2)
+ panic("freed too little: %zu < %ld / 2 (%p)",
+ freedsize, size, addr);
/*
* Check for returns of data that do not point to the
* beginning of the allocation.