Ada任务声明导致内存泄漏

时间:2012-03-03 21:09:20

标签: memory-leaks valgrind ada

我有以下小小的Ada计划:

procedure Leaky_Main is 
   task Beer;
   task body Beer is 
   begin 
      null;
   end Beer;
begin 
   null;
end Leaky_Main;

所有相当基本的,但是当我像这样编译时:

gnatmake -g -gnatwI leaky_main.adb

然后通过Valgrind运行它:

valgrind --tool=memcheck -v --leak-check=full --read-var-info=yes --leak-check=full --show-reachable=yes ./leaky_main

我收到以下错误摘要:

==2882== 2,104 bytes in 1 blocks are still reachable in loss record 1 of 1
==2882==    at 0x4028876: malloc (vg_replace_malloc.c:236)
==2882==    by 0x42AD3B8: __gnat_malloc (in /usr/lib/i386-linux-gnu/libgnat-4.4.so.1)
==2882==    by 0x40615FF: system__task_primitives__operations__new_atcb (in /usr/lib/i386-linux-gnu/libgnarl-4.4.so.1)
==2882==    by 0x406433C: system__tasking__initialize (in /usr/lib/i386-linux-gnu/libgnarl-4.4.so.1)
==2882==    by 0x4063C86: system__tasking__initialization__init_rts (in /usr/lib/i386-linux-gnu/libgnarl-4.4.so.1)
==2882==    by 0x4063DA6: system__tasking__initialization___elabb (in /usr/lib/i386-linux-gnu/libgnarl-4.4.so.1)
==2882==    by 0x8049ADA: adainit (b~leaky_main.adb:142)
==2882==    by 0x8049B7C: main (b~leaky_main.adb:189)
==2882== 
==2882== LEAK SUMMARY:
==2882==    definitely lost: 0 bytes in 0 blocks
==2882==    indirectly lost: 0 bytes in 0 blocks
==2882==      possibly lost: 0 bytes in 0 blocks
==2882==    still reachable: 2,104 bytes in 1 blocks
==2882==         suppressed: 0 bytes in 0 blocks
==2882== 
==2882== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 from 6)
--2882-- 
--2882-- used_suppression:     21 U1004-ARM-_dl_relocate_object
==2882== 
==2882== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 from 6)

有谁知道为什么这被报告为错误? 我相当确定没有实际的泄漏,但我想知道为什么/如何发生。

谢谢,

2 个答案:

答案 0 :(得分:2)

有问题的分配看起来是任务控制块(TCB)。任务完成后必须保留此项,以便您可以说

if Beer’Terminated then
   ...

所以我认为这可能是valgrind检查时的假象。

我只是遇到了分配任务的地方;在释放任务之前必须等到’TerminatedTrue,否则GNAT很高兴地释放了堆栈,但是默默地没有解除分配TCB,导致像你这样的真正泄漏。 AdaCore最近解决了这个问题(我没有参考,它是在他们的开发者日志中)。

答案 1 :(得分:0)

您应该使用deleaker进行调试。我更喜欢它)