Joe Nelson <[email protected]> writes:
> Omar Polo wrote: >> There's a built-in mechanisms to check for memory leaks: >> >> https://www.drijf.net/malloc/ >> >> don't know if it still applies, I tried only once and was like a couple >> of years ago (if not more). > > Thanks for the tip, Omar. I just tried compiling malloc.c with MALLOC_STATS > defined, but I got a compiler error: > > clang -O2 -pipe -g -Wimplicit -I/usr/src/lib/libc/include > -I/usr/src/lib/libc/hidden \ > -D__LIBC__ -Werror-implicit-function-declaration -include > namespace.h \ > -Werror=deprecated-declarations -DAPIWARN -DYP > -I/usr/src/lib/libc/yp \ > -I/usr/src/lib/libc -I/usr/src/lib/libc/gdtoa > \ > -I/usr/src/lib/libc/arch/amd64/gdtoa -DINFNAN_CHECK > -DMULTIPLE_THREADS \ > -DNO_FENV_H -DUSE_LOCALE -I/usr/src/lib/libc > -I/usr/src/lib/libc/citrus \ > -DRESOLVSORT -DFLOATING_POINT -DPRINTF_WIDE_CHAR -DSCANF_WIDE_CHAR > -DFUTEX -MD \ > -MP -c /usr/src/lib/libc/stdlib/malloc.c -o malloc.o > > /usr/src/lib/libc/stdlib/malloc.c:1613:14: error: use of undeclared > identifier 'd' > > STATS_SUB(d->malloc_used, roldsz - rnewsz); > ^ > 1 error generated. > > Malloc source version: > $OpenBSD: malloc.c,v 1.270 2021/04/09 06:05:21 otto Exp $ > System: > 6.9 stable that seems to be a typo? not tried, but compiles :) Index: malloc.c =================================================================== RCS file: /home/cvs/src/lib/libc/stdlib/malloc.c,v retrieving revision 1.270 diff -u -p -r1.270 malloc.c --- malloc.c 9 Apr 2021 06:05:21 -0000 1.270 +++ malloc.c 23 Jul 2021 16:01:26 -0000 @@ -1610,7 +1610,7 @@ orealloc(struct dir_info **argpool, void } if (munmap((char *)r->p + rnewsz, roldsz - rnewsz)) wrterror(pool, "munmap %p", (char *)r->p + rnewsz); - STATS_SUB(d->malloc_used, roldsz - rnewsz); + STATS_SUB(pool->malloc_used, roldsz - rnewsz); r->size = gnewsz; if (MALLOC_MOVE_COND(gnewsz)) { void *pp = MALLOC_MOVE(r->p, gnewsz);

