summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasou <>2023-09-09 06:52:40 +0000
committerasou <>2023-09-09 06:52:40 +0000
commite972f5da5cac1abe94d601451d52cb4f9e0118bc (patch)
treea816d4bb12ebeb517a94b21c3199644a3c1d6fee
parenta6150f86be846b0e2ed8286d30404edc545f036c (diff)
downloadopenbsd-e972f5da5cac1abe94d601451d52cb4f9e0118bc.tar.gz
openbsd-e972f5da5cac1abe94d601451d52cb4f9e0118bc.tar.bz2
openbsd-e972f5da5cac1abe94d601451d52cb4f9e0118bc.zip
Print waring message when not allocated memory in putleakinfo().
ok otto.
-rw-r--r--src/lib/libc/stdlib/malloc.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index c09e1541e5..814a417145 100644
--- a/src/lib/libc/stdlib/malloc.c
+++ b/src/lib/libc/stdlib/malloc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: malloc.c,v 1.289 2023/06/30 06:24:58 otto Exp $ */ 1/* $OpenBSD: malloc.c,v 1.290 2023/09/09 06:52:40 asou Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -2338,6 +2338,22 @@ RBT_PROTOTYPE(leaktree, leaknode, entry, leakcmp);
2338RBT_GENERATE(leaktree, leaknode, entry, leakcmp); 2338RBT_GENERATE(leaktree, leaknode, entry, leakcmp);
2339 2339
2340static void 2340static void
2341wrtwarning(const char *func, char *msg, ...)
2342{
2343 int saved_errno = errno;
2344 va_list ap;
2345
2346 dprintf(STDERR_FILENO, "%s(%d) in %s(): ", __progname,
2347 getpid(), func != NULL ? func : "unknown");
2348 va_start(ap, msg);
2349 vdprintf(STDERR_FILENO, msg, ap);
2350 va_end(ap);
2351 dprintf(STDERR_FILENO, "\n");
2352
2353 errno = saved_errno;
2354}
2355
2356static void
2341putleakinfo(struct leaktree *leaks, void *f, size_t sz, int cnt) 2357putleakinfo(struct leaktree *leaks, void *f, size_t sz, int cnt)
2342{ 2358{
2343 struct leaknode key, *p; 2359 struct leaknode key, *p;
@@ -2353,8 +2369,10 @@ putleakinfo(struct leaktree *leaks, void *f, size_t sz, int cnt)
2353 if (page == NULL || 2369 if (page == NULL ||
2354 used >= MALLOC_PAGESIZE / sizeof(struct leaknode)) { 2370 used >= MALLOC_PAGESIZE / sizeof(struct leaknode)) {
2355 page = MMAP(MALLOC_PAGESIZE, 0); 2371 page = MMAP(MALLOC_PAGESIZE, 0);
2356 if (page == MAP_FAILED) 2372 if (page == MAP_FAILED) {
2373 wrtwarning(__func__, strerror(errno));
2357 return; 2374 return;
2375 }
2358 used = 0; 2376 used = 0;
2359 } 2377 }
2360 p = &page[used++]; 2378 p = &page[used++];