如何检查Guile扩展模块中的内存泄漏?

时间:2021-03-15 07:02:33

I develop an extension module for Guile, written in C. This extension module embeds a Python interpreter.

我为Guile开发了一个扩展模块,用C语言编写。这个扩展模块嵌入了一个Python解释器。

Since this extension module invokes the Python interpreter, I need to verify that it properly manages the memory occupied by Python objects.

由于此扩展模块调用Python解释器,我需要验证它是否正确管理Python对象占用的内存。

I found that the Python interpreter is well-behaved in its own memory handling, so that by running valgrind I can find memory leaks due to bugs in my own Python interpreter embedding code, if there are no other interfering factors.

我发现Python解释器在其自己的内存处理中表现良好,因此通过运行valgrind,我可以发现由于我自己的Python解释器嵌入代码中的错误导致的内存泄漏,如果没有其他干扰因素的话。

However, when I run Guile under valgrind, valgrind reports memory leaks. Such memory leaks obscure any memory leaks due to my own code.

但是,当我在valgrind下运行Guile时,valgrind会报告内存泄漏。这种内存泄漏会掩盖由于我自己的代码导致的任何内存泄漏。

The question is what can I do to separate memory leaks due to bugs in my code from memory leaks reported by valgrind as due to Guile. Another tool instead of valgrind? Special valgrind options? Give up and rely upon manual code walkthrough?

问题是我可以做些什么来分离由于我的代码中的错误而导致的内存泄漏与valgrind报告的内存泄漏(由于Guile导致的内容泄漏)。另一个工具而不是valgrind?特殊的valgrind选项?放弃并依赖手动代码演练?

1 个解决方案

#1


5  

You've got a couple options. One is to write a supressions file for valgrind that turns off reporting of stuff that you're not working on. Python has such a file, for example: http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp

你有几个选择。一种是为valgrind写一个supressions文件,关闭你没有工作的东西的报告。 Python有这样一个文件,例如:http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp

If valgrind doesn't like your setup, another possibility is using libmudflap; you compile your program with gcc -fmudflap -lmudflap, and the resulting code is instrumented for pointer debugging. Described in the gcc docs, and here: http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging

如果valgrind不喜欢你的设置,另一种可能是使用libmudflap;使用gcc -fmudflap -lmudflap编译程序,并对结果代码进行指针调试。在gcc文档中描述,并在这里:http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging

#1


5  

You've got a couple options. One is to write a supressions file for valgrind that turns off reporting of stuff that you're not working on. Python has such a file, for example: http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp

你有几个选择。一种是为valgrind写一个supressions文件,关闭你没有工作的东西的报告。 Python有这样一个文件,例如:http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp

If valgrind doesn't like your setup, another possibility is using libmudflap; you compile your program with gcc -fmudflap -lmudflap, and the resulting code is instrumented for pointer debugging. Described in the gcc docs, and here: http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging

如果valgrind不喜欢你的设置,另一种可能是使用libmudflap;使用gcc -fmudflap -lmudflap编译程序,并对结果代码进行指针调试。在gcc文档中描述,并在这里:http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging