summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/malloc.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2018-11-21 06:57:04 +0000
committerotto <otto@openbsd.org>2018-11-21 06:57:04 +0000
commitacb3f83f5f2f906963ced527da63eb9d54d45cd5 (patch)
tree39a92d8c41fce34de479bc4fae6271334afc3d1c /lib/libc/stdlib/malloc.c
parentwhen printing essids return the number of chars we printed, like printf (diff)
downloadwireguard-openbsd-acb3f83f5f2f906963ced527da63eb9d54d45cd5.tar.xz
wireguard-openbsd-acb3f83f5f2f906963ced527da63eb9d54d45cd5.zip
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
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r--lib/libc/stdlib/malloc.c79
1 files changed, 1 insertions, 78 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 513defccbcb..0912b904b82 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/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 <otto@drijf.net>
* Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -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)
{