On Thu, Jun 08, 2017 at 10:30:34AM -0400, Chet Ramey wrote: [...] > That would be strange behavior. If it complains about that, why doesn't it > complain about all memory that bash holds onto but doesn't free before it > exits?
Hm. You're right. It seems to be glibc's fault here. The leak happens when I turn on compiler optimizations, but it goes away if I turn them off. Which means it's not bash. Sorry about the noise :-) == ASAN / -O2 == dualbus@debian:~/src/gnu/bash-build$ CFLAGS='-O2 -fsanitize=address -fno-omit-frame-pointer' LDFLAGS=-lasan ../bash/configure --without-bash-malloc && make -j4 [...] rm -f bash gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/sh -lasan -rdynamic -O2 -fsanitize=address -fno-omit-frame-pointer -Wno-parentheses -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -ldl ./lib/sh/libsh.a(tmpfile.o): In function `sh_mktmpname': tmpfile.c:(.text+0x161): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' ls -l bash -rwxr-x--- 1 dualbus dualbus 2916104 Jun 8 09:40 bash size bash text data bss dec hex filename 2444962 287960 81184 2814106 2af09a bash dualbus@debian:~/src/gnu/bash-build$ ./bash bash-4.4$ echo hi hi bash-4.4$ exit exit ================================================================= ==3830==ERROR: LeakSanitizer: detected memory leaks Direct leak of 12 byte(s) in 1 object(s) allocated from: #0 0x7f4981cd1d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28) #1 0x55d742038866 in xmalloc (/home/dualbus/src/gnu/bash-build/bash+0x14f866) #2 0x55d74202adf2 in set_default_locale (/home/dualbus/src/gnu/bash-build/bash+0x141df2) #3 0x55d741f697f0 in main (/home/dualbus/src/gnu/bash-build/bash+0x807f0) #4 0x7f49814642b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0) SUMMARY: AddressSanitizer: 12 byte(s) leaked in 1 allocation(s). == Valgrind / -O2 == dualbus@debian:~/src/gnu/bash-build$ CFLAGS='-O2 -fno-omit-frame-pointer' LDFLAGS= ../bash/configure --without-bash-malloc && make -j4 [...] rm -f bash gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/sh -rdynamic -O2 -fno-omit-frame-pointer -Wno-parentheses -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -ldl ./lib/sh/libsh.a(tmpfile.o): In function `sh_mktmpname': tmpfile.c:(.text+0x161): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' ls -l bash -rwxr-x--- 1 dualbus dualbus 1321952 Jun 8 09:51 bash size bash text data bss dec hex filename 1114390 47940 40496 1202826 125a8a bash dualbus@debian:~/src/gnu/bash-build$ valgrind ./bash ==18244== Memcheck, a memory error detector ==18244== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==18244== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info ==18244== Command: ./bash ==18244== bash-4.4$ echo hi hi bash-4.4$ exit exit ==18244== ==18244== HEAP SUMMARY: ==18244== in use at exit: 347,357 bytes in 2,879 blocks ==18244== total heap usage: 4,406 allocs, 1,527 frees, 607,170 bytes allocated ==18244== ==18244== LEAK SUMMARY: ==18244== definitely lost: 12 bytes in 1 blocks ==18244== indirectly lost: 0 bytes in 0 blocks ==18244== possibly lost: 0 bytes in 0 blocks ==18244== still reachable: 347,345 bytes in 2,878 blocks ==18244== suppressed: 0 bytes in 0 blocks ==18244== Rerun with --leak-check=full to see details of leaked memory ==18244== ==18244== For counts of detected and suppressed errors, rerun with: -v ==18244== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) == ASAN / -O0 == dualbus@debian:~/src/gnu/bash-build$ CFLAGS='-O0 -fsanitize=address -fno-omit-frame-pointer' LDFLAGS=-lasan ../bash/configure --without-bash-malloc && make -j4 [...] rm -f bash gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/sh -lasan -rdynamic -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-parentheses -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -ldl ./lib/sh/libsh.a(tmpfile.o): In function `sh_mktmpname': tmpfile.c:(.text+0x3e4): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' ls -l bash -rwxr-x--- 1 dualbus dualbus 3433608 Jun 8 09:56 bash size bash text data bss dec hex filename 2933580 297264 83904 3314748 32943c bash dualbus@debian:~/src/gnu/bash-build$ ./bash bash-4.4$ echo hi hi bash-4.4$ exit == Valgrind / -O0 == dualbus@debian:~/src/gnu/bash-build$ CFLAGS='-O0 -fno-omit-frame-pointer' LDFLAGS= ../bash/configure --without-bash-malloc && make -j4 [...] rm -f bash gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/sh -rdynamic -O0 -fno-omit-frame-pointer -Wno-parentheses -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o -lbuiltins -lglob -lsh -lreadline -lhistory -ltermcap -ltilde -ldl ./lib/sh/libsh.a(tmpfile.o): In function `sh_mktmpname': tmpfile.c:(.text+0x25e): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp' ls -l bash -rwxr-x--- 1 dualbus dualbus 1511808 Jun 8 10:00 bash size bash text data bss dec hex filename 1286664 48380 41072 1376116 14ff74 bash dualbus@debian:~/src/gnu/bash-build$ valgrind ./bash ==333== Memcheck, a memory error detector ==333== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==333== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info ==333== Command: ./bash ==333== bash-4.4$ echo hi hi bash-4.4$ exit exit ==333== ==333== HEAP SUMMARY: ==333== in use at exit: 347,442 bytes in 2,885 blocks ==333== total heap usage: 4,412 allocs, 1,527 frees, 607,323 bytes allocated ==333== ==333== LEAK SUMMARY: ==333== definitely lost: 0 bytes in 0 blocks ==333== indirectly lost: 0 bytes in 0 blocks ==333== possibly lost: 0 bytes in 0 blocks ==333== still reachable: 347,442 bytes in 2,885 blocks ==333== suppressed: 0 bytes in 0 blocks ==333== Rerun with --leak-check=full to see details of leaked memory ==333== ==333== For counts of detected and suppressed errors, rerun with: -v ==333== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) -- Eduardo Bustamante https://dualbus.me/