|
@ -1,4 +1,4 @@ |
|
|
/* $OpenBSD: malloc.c,v 1.221 2017/04/13 18:32:55 otto Exp $ */ |
|
|
|
|
|
|
|
|
/* $OpenBSD: malloc.c,v 1.222 2017/04/17 16:36:35 otto Exp $ */ |
|
|
/* |
|
|
/* |
|
|
* Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
|
|
* Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
|
|
* Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
|
|
* Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
|
@ -261,7 +261,7 @@ hash(void *p) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static inline |
|
|
static inline |
|
|
struct dir_info *getpool(void) |
|
|
|
|
|
|
|
|
struct dir_info *getpool(void) |
|
|
{ |
|
|
{ |
|
|
if (!mopts.malloc_mt) |
|
|
if (!mopts.malloc_mt) |
|
|
return mopts.malloc_pool[0]; |
|
|
return mopts.malloc_pool[0]; |
|
@ -1012,7 +1012,7 @@ malloc_bytes(struct dir_info *d, size_t size, void *f) |
|
|
|
|
|
|
|
|
/* Adjust to the real offset of that chunk */ |
|
|
/* Adjust to the real offset of that chunk */ |
|
|
k += (lp - bp->bits) * MALLOC_BITS; |
|
|
k += (lp - bp->bits) * MALLOC_BITS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mopts.chunk_canaries) |
|
|
if (mopts.chunk_canaries) |
|
|
bp->bits[bp->offset + k] = size; |
|
|
bp->bits[bp->offset + k] = size; |
|
|
|
|
|
|
|
@ -1266,7 +1266,7 @@ malloc(size_t size) |
|
|
} |
|
|
} |
|
|
_MALLOC_LOCK(d->mutex); |
|
|
_MALLOC_LOCK(d->mutex); |
|
|
d->func = "malloc"; |
|
|
d->func = "malloc"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (d->active++) { |
|
|
if (d->active++) { |
|
|
malloc_recurse(d); |
|
|
malloc_recurse(d); |
|
|
return NULL; |
|
|
return NULL; |
|
@ -1326,7 +1326,7 @@ ofree(struct dir_info *argpool, void *p, int clear, int check, size_t argsz) |
|
|
if (r != NULL) |
|
|
if (r != NULL) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
if (r == NULL) |
|
|
if (r == NULL) |
|
|
wrterror(pool, "bogus pointer (double free?) %p", p); |
|
|
wrterror(pool, "bogus pointer (double free?) %p", p); |
|
|
} |
|
|
} |
|
@ -1336,9 +1336,9 @@ ofree(struct dir_info *argpool, void *p, int clear, int check, size_t argsz) |
|
|
if (sz <= MALLOC_MAXCHUNK) { |
|
|
if (sz <= MALLOC_MAXCHUNK) { |
|
|
if (mopts.chunk_canaries) { |
|
|
if (mopts.chunk_canaries) { |
|
|
struct chunk_info *info = |
|
|
struct chunk_info *info = |
|
|
(struct chunk_info *)r->size; |
|
|
|
|
|
|
|
|
(struct chunk_info *)r->size; |
|
|
uint32_t chunknum = |
|
|
uint32_t chunknum = |
|
|
find_chunknum(pool, r, p, 0); |
|
|
|
|
|
|
|
|
find_chunknum(pool, r, p, 0); |
|
|
|
|
|
|
|
|
if (info->bits[info->offset + chunknum] < |
|
|
if (info->bits[info->offset + chunknum] < |
|
|
argsz) |
|
|
argsz) |
|
@ -1346,7 +1346,7 @@ ofree(struct dir_info *argpool, void *p, int clear, int check, size_t argsz) |
|
|
" < %zu", |
|
|
" < %zu", |
|
|
info->bits[info->offset + chunknum], |
|
|
info->bits[info->offset + chunknum], |
|
|
argsz); |
|
|
argsz); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} else if (sz - mopts.malloc_guard < argsz) |
|
|
} else if (sz - mopts.malloc_guard < argsz) |
|
|
wrterror(pool, "recorded old size %zu < %zu", |
|
|
wrterror(pool, "recorded old size %zu < %zu", |
|
|
sz - mopts.malloc_guard, argsz); |
|
|
sz - mopts.malloc_guard, argsz); |
|
@ -1489,7 +1489,7 @@ orealloc(struct dir_info *argpool, void *p, size_t newsz, void *f) |
|
|
void *q, *ret; |
|
|
void *q, *ret; |
|
|
int i; |
|
|
int i; |
|
|
uint32_t chunknum; |
|
|
uint32_t chunknum; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pool = argpool; |
|
|
pool = argpool; |
|
|
|
|
|
|
|
|
if (p == NULL) |
|
|
if (p == NULL) |
|
@ -1510,7 +1510,7 @@ orealloc(struct dir_info *argpool, void *p, size_t newsz, void *f) |
|
|
if (r != NULL) |
|
|
if (r != NULL) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
if (r == NULL) |
|
|
if (r == NULL) |
|
|
wrterror(pool, "bogus pointer (double free?) %p", p); |
|
|
wrterror(pool, "bogus pointer (double free?) %p", p); |
|
|
} |
|
|
} |
|
@ -1759,7 +1759,7 @@ orecallocarray(struct dir_info *argpool, void *p, size_t oldsize, |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
pool = argpool; |
|
|
pool = argpool; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p == NULL) |
|
|
if (p == NULL) |
|
|
return omalloc(pool, newsize, 1, f); |
|
|
return omalloc(pool, newsize, 1, f); |
|
|
|
|
|
|
|
@ -1785,7 +1785,7 @@ orecallocarray(struct dir_info *argpool, void *p, size_t oldsize, |
|
|
if (r == NULL) |
|
|
if (r == NULL) |
|
|
wrterror(pool, "bogus pointer (double free?) %p", p); |
|
|
wrterror(pool, "bogus pointer (double free?) %p", p); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REALSIZE(sz, r); |
|
|
REALSIZE(sz, r); |
|
|
if (sz <= MALLOC_MAXCHUNK) { |
|
|
if (sz <= MALLOC_MAXCHUNK) { |
|
|
if (mopts.chunk_canaries) { |
|
|
if (mopts.chunk_canaries) { |
|
@ -1846,7 +1846,7 @@ recallocarray_p(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) |
|
|
return NULL; |
|
|
return NULL; |
|
|
} |
|
|
} |
|
|
oldsize = oldnmemb * size; |
|
|
oldsize = oldnmemb * size; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Don't bother too much if we're shrinking just a bit, |
|
|
* Don't bother too much if we're shrinking just a bit, |
|
|
* we do not shrink for series of small steps, oh well. |
|
|
* we do not shrink for series of small steps, oh well. |
|
@ -1895,7 +1895,7 @@ recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) |
|
|
|
|
|
|
|
|
_MALLOC_LOCK(d->mutex); |
|
|
_MALLOC_LOCK(d->mutex); |
|
|
d->func = "recallocarray"; |
|
|
d->func = "recallocarray"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && |
|
|
if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && |
|
|
newnmemb > 0 && SIZE_MAX / newnmemb < size) { |
|
|
newnmemb > 0 && SIZE_MAX / newnmemb < size) { |
|
|
_MALLOC_UNLOCK(d->mutex); |
|
|
_MALLOC_UNLOCK(d->mutex); |
|
|