Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern - kern_realloc: fix a recent regression, use correc...



details:   https://anonhg.NetBSD.org/src/rev/bde60a690785
branches:  trunk
changeset: 773259:bde60a690785
user:      rmind <rmind%NetBSD.org@localhost>
date:      Mon Jan 30 01:56:47 2012 +0000

description:
- kern_realloc: fix a recent regression, use correct size of current allocation.
- kern_malloc: constify.

diffstat:

 sys/kern/kern_malloc.c |  14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diffs (50 lines):

diff -r f26173e4e252 -r bde60a690785 sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c    Mon Jan 30 01:54:08 2012 +0000
+++ b/sys/kern/kern_malloc.c    Mon Jan 30 01:56:47 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_malloc.c,v 1.135 2012/01/28 23:09:06 rmind Exp $  */
+/*     $NetBSD: kern_malloc.c,v 1.136 2012/01/30 01:56:47 rmind Exp $  */
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.135 2012/01/28 23:09:06 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.136 2012/01/30 01:56:47 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -91,7 +91,8 @@
 kmutex_t malloc_lock;
 
 struct malloc_header {
-       size_t mh_size;
+       /* Total size, include the header. */
+       size_t          mh_size;
 };
 
 /*
@@ -106,10 +107,9 @@
 kern_malloc(unsigned long size, struct malloc_type *ksp, int flags)
 #endif /* MALLOCLOG */
 {
+       const int kmflags = (flags & M_NOWAIT) ? KM_NOSLEEP : KM_SLEEP;
+       const size_t allocsize = sizeof(struct malloc_header) + size;
        struct malloc_header *mh;
-       int kmflags = ((flags & M_NOWAIT) != 0
-           ? KM_NOSLEEP : KM_SLEEP);
-       size_t allocsize = sizeof(struct malloc_header) + size;
        void *p;
 
        p = kmem_intr_alloc(allocsize, kmflags);
@@ -178,7 +178,7 @@
        mh = curaddr;
        mh--;
 
-       cursize = mh->mh_size;
+       cursize = mh->mh_size - sizeof(struct malloc_header);
 
        /*
         * If we already actually have as much as they want, we're done.



Home | Main Index | Thread Index | Old Index