From: asou Date: Sat, 9 Sep 2023 06:52:40 +0000 (+0000) Subject: Print waring message when not allocated memory in putleakinfo(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=db142dbd5306db33f3a0629b19a8c3dca083b7dc;p=openbsd Print waring message when not allocated memory in putleakinfo(). ok otto. --- diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index c09e1541e5f..814a4171450 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.289 2023/06/30 06:24:58 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.290 2023/09/09 06:52:40 asou Exp $ */ /* * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky @@ -2337,6 +2337,22 @@ RBT_HEAD(leaktree, leaknode); RBT_PROTOTYPE(leaktree, leaknode, entry, leakcmp); RBT_GENERATE(leaktree, leaknode, entry, leakcmp); +static void +wrtwarning(const char *func, char *msg, ...) +{ + int saved_errno = errno; + va_list ap; + + dprintf(STDERR_FILENO, "%s(%d) in %s(): ", __progname, + getpid(), func != NULL ? func : "unknown"); + va_start(ap, msg); + vdprintf(STDERR_FILENO, msg, ap); + va_end(ap); + dprintf(STDERR_FILENO, "\n"); + + errno = saved_errno; +} + static void putleakinfo(struct leaktree *leaks, void *f, size_t sz, int cnt) { @@ -2353,8 +2369,10 @@ putleakinfo(struct leaktree *leaks, void *f, size_t sz, int cnt) if (page == NULL || used >= MALLOC_PAGESIZE / sizeof(struct leaknode)) { page = MMAP(MALLOC_PAGESIZE, 0); - if (page == MAP_FAILED) + if (page == MAP_FAILED) { + wrtwarning(__func__, strerror(errno)); return; + } used = 0; } p = &page[used++];