From 9d3c55760e9cc7dca8b55958537265f1162dc63c Mon Sep 17 00:00:00 2001 From: otto <> Date: Wed, 21 Nov 2018 06:57:04 +0000 Subject: Introducing malloc_usable_size() was a mistake. While some other libs have it, it is a function that is considered harmful, so: Delete malloc_usable_size(). It is a function that blurs the line between malloc managed memory and application managed memory and exposes some of the internal workings of malloc. If an application relies on that, it is likely to break using another implementation of malloc. If you want usable size x, just allocate x bytes. ok deraadt@ and other devs --- src/lib/libc/stdlib/malloc.c | 79 +------------------------------------------- 1 file changed, 1 insertion(+), 78 deletions(-) (limited to 'src/lib/libc/stdlib/malloc.c') diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 513defccbc..0912b904b8 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.253 2018/11/19 22:50:24 guenther Exp $ */ +/* $OpenBSD: malloc.c,v 1.254 2018/11/21 06:57:04 otto Exp $ */ /* * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky @@ -1466,83 +1466,6 @@ freezero(void *ptr, size_t sz) } DEF_WEAK(freezero); -static size_t -osize(struct dir_info *argpool, void *p) -{ - struct dir_info *pool; - struct region_info *r; - char *saved_function; - size_t sz; - int i; - - pool = argpool; - r = find(pool, p); - if (r == NULL) { - if (mopts.malloc_mt) { - for (i = 0; i < _MALLOC_MUTEXES; i++) { - if (i == argpool->mutex) - continue; - pool->active--; - _MALLOC_UNLOCK(pool->mutex); - pool = mopts.malloc_pool[i]; - _MALLOC_LOCK(pool->mutex); - pool->active++; - r = find(pool, p); - if (r != NULL) { - saved_function = pool->func; - pool->func = argpool->func; - break; - } - } - } - if (r == NULL) - wrterror(argpool, "bogus pointer (double free?) %p", p); - } - - REALSIZE(sz, r); - if (sz > MALLOC_MAXCHUNK) { - if (MALLOC_MOVE_COND(sz)) - sz = MALLOC_PAGESIZE - ((char *)p - (char *)r->p); - else - sz = PAGEROUND(sz); - } - if (argpool != pool) { - pool->active--; - pool->func = saved_function; - _MALLOC_UNLOCK(pool->mutex); - _MALLOC_LOCK(argpool->mutex); - argpool->active++; - } - return sz; -} - -size_t -malloc_usable_size(void *ptr) -{ - struct dir_info *d; - int saved_errno = errno; - size_t sz; - - /* This is legal. */ - if (ptr == NULL) - return 0; - - d = getpool(); - if (d == NULL) - wrterror(d, "malloc_usable_size() called before allocation"); - _MALLOC_LOCK(d->mutex); - d->func = "malloc_usable_size"; - if (d->active++) { - malloc_recurse(d); - return 0; - } - sz = osize(d, ptr); - d->active--; - _MALLOC_UNLOCK(d->mutex); - errno = saved_errno; - return sz; -} - static void * orealloc(struct dir_info *argpool, void *p, size_t newsz, void *f) { -- cgit v1.2.3-55-g6feb