bash正在泄漏内存吗?

bash正在泄漏内存吗?,bash,memory-leaks,valgrind,Bash,Memory Leaks,Valgrind,我正在运行Ubuntu 18.10上发布的bashv4.4.19(1)。如果我在一个简单的脚本上运行valgrind(甚至bash--version),我会发现我确实丢失了12个字节的内存,并且仍然可以访问大约46kB的内存。仍然可以访问的内存并没有给我带来太多麻烦,因为我知道bash将处理进程处理和释放,但我不明白的是为什么会丢失这12个字节 下面是我正在使用的一个简单测试脚本的示例(文件名为t.bash): 我还尝试了在脚本末尾使用unset A,这会导致valgrind输出的“仍然可以访问

我正在运行Ubuntu 18.10上发布的
bash
v4.4.19(1)。如果我在一个简单的脚本上运行
valgrind
(甚至
bash--version
),我会发现我确实丢失了12个字节的内存,并且仍然可以访问大约46kB的内存。仍然可以访问的内存并没有给我带来太多麻烦,因为我知道bash将处理进程处理和释放,但我不明白的是为什么会丢失这12个字节

下面是我正在使用的一个简单测试脚本的示例(文件名为t.bash):

我还尝试了在脚本末尾使用
unset A
,这会导致
valgrind
输出的“仍然可以访问”部分减少约14个字节(这很有意义)。我将valgrind称为
valgrind./t.bash
(或者甚至
valgrind bash--version
,只是想看看它是否也泄漏了,确实如此)

这正常吗?在更丰富的脚本中,我发现了相同的结果,bash的每一个派生都“肯定丢失”了12个字节

上述脚本的valgrind输出示例:

ctimm@gordon:~$ valgrind ./t.bash 
==37810== Memcheck, a memory error detector
==37810== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==37810== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==37810== Command: ./t.bash
==37810== 
3
==37810== 
==37810== HEAP SUMMARY:
==37810==     in use at exit: 45,729 bytes in 641 blocks
==37810==   total heap usage: 766 allocs, 125 frees, 55,160 bytes allocated
==37810== 
==37810== LEAK SUMMARY:
==37810==    definitely lost: 12 bytes in 1 blocks
==37810==    indirectly lost: 0 bytes in 0 blocks
==37810==      possibly lost: 0 bytes in 0 blocks
==37810==    still reachable: 45,717 bytes in 640 blocks
==37810==         suppressed: 0 bytes in 0 blocks
==37810== Rerun with --leak-check=full to see details of leaked memory
==37810== 
==37810== For counts of detected and suppressed errors, rerun with: -v
==37810== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
对于运行valgrind over
bash--version
,进行全面泄漏检查,显示所有泄漏类型:

ctimm@gordon:~$ valgrind --leak-check=full --show-leak-kinds=all bash --version
==39097== Memcheck, a memory error detector
==39097== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==39097== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==39097== Command: bash --version
==39097== 
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
==39097== 
==39097== HEAP SUMMARY:
==39097==     in use at exit: 17 bytes in 2 blocks
==39097==   total heap usage: 153 allocs, 151 frees, 21,051 bytes allocated
==39097== 
==39097== 5 bytes in 1 blocks are still reachable in loss record 1 of 2
==39097==    at 0x483774F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==39097==    by 0x19007D: xmalloc (in /bin/bash)
==39097==    by 0x1351FA: main (in /bin/bash)
==39097== 
==39097== 12 bytes in 1 blocks are definitely lost in loss record 2 of 2
==39097==    at 0x483774F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==39097==    by 0x19007D: xmalloc (in /bin/bash)
==39097==    by 0x189A7A: set_default_locale (in /bin/bash)
==39097==    by 0x134EA6: main (in /bin/bash)
==39097== 
==39097== LEAK SUMMARY:
==39097==    definitely lost: 12 bytes in 1 blocks
==39097==    indirectly lost: 0 bytes in 0 blocks
==39097==      possibly lost: 0 bytes in 0 blocks
==39097==    still reachable: 5 bytes in 1 blocks
==39097==         suppressed: 0 bytes in 0 blocks
==39097== 
==39097== For counts of detected and suppressed errors, rerun with: -v
==39097== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
ctimm@gordon:~$valgrind--leak check=full--show leak kinds=all bash--version
==39097==Memcheck,内存错误检测器
==39097==2002-2017年版权(C)和GNU GPL'd,朱利安·苏厄德等人。
==39097==使用Valgrind-3.13.0和LibVEX;使用-h重新运行以获取版权信息
==39097==命令:bash--version
==39097== 
GNUBash,版本4.4.19(1)-发行版(x86_64-pc-linux-GNU)
版权所有(C)2016免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件;您可以自由更改和重新分发它。
在法律允许的范围内,不存在任何担保。
==39097== 
==39097==堆摘要:
==39097==在出口处使用:2个块中有17个字节
==39097==总堆使用率:153个alloc,151个free,21051个字节分配
==39097== 
==39097==1个块中的5个字节仍然可以在丢失记录1(共2个)中访问
==39097==at 0x483774F:malloc(在/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so中)
==39097==by 0x19007D:xmalloc(in/bin/bash)
==39097==0x1351FA:main(in/bin/bash)
==39097== 
==39097==1个块中的12个字节在丢失记录2(共2个)中肯定丢失
==39097==at 0x483774F:malloc(在/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so中)
==39097==by 0x19007D:xmalloc(in/bin/bash)
==39097==by 0x189A7A:set_default_locale(在/bin/bash中)
==39097==by0x134ea6:main(in/bin/bash)
==39097== 
==39097==泄漏汇总:
==39097==肯定丢失:1个块中有12个字节
==39097==间接丢失:0个块中有0个字节
==39097==可能丢失:0个块中有0个字节
==39097==仍然可访问:1个块中有5个字节
==39097==抑制:0个块中有0个字节
==39097== 
==39097==对于检测到的和抑制的错误计数,请使用:-v重新运行
==39097==错误摘要:1个上下文中的1个错误(已抑制:0中的0)

谢谢。

似乎泄漏发生在setlocale中,也许可以提供帮助
ctimm@gordon:~$ valgrind --leak-check=full --show-leak-kinds=all bash --version
==39097== Memcheck, a memory error detector
==39097== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==39097== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==39097== Command: bash --version
==39097== 
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
==39097== 
==39097== HEAP SUMMARY:
==39097==     in use at exit: 17 bytes in 2 blocks
==39097==   total heap usage: 153 allocs, 151 frees, 21,051 bytes allocated
==39097== 
==39097== 5 bytes in 1 blocks are still reachable in loss record 1 of 2
==39097==    at 0x483774F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==39097==    by 0x19007D: xmalloc (in /bin/bash)
==39097==    by 0x1351FA: main (in /bin/bash)
==39097== 
==39097== 12 bytes in 1 blocks are definitely lost in loss record 2 of 2
==39097==    at 0x483774F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==39097==    by 0x19007D: xmalloc (in /bin/bash)
==39097==    by 0x189A7A: set_default_locale (in /bin/bash)
==39097==    by 0x134EA6: main (in /bin/bash)
==39097== 
==39097== LEAK SUMMARY:
==39097==    definitely lost: 12 bytes in 1 blocks
==39097==    indirectly lost: 0 bytes in 0 blocks
==39097==      possibly lost: 0 bytes in 0 blocks
==39097==    still reachable: 5 bytes in 1 blocks
==39097==         suppressed: 0 bytes in 0 blocks
==39097== 
==39097== For counts of detected and suppressed errors, rerun with: -v
==39097== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)