How to check for memory leaks in Guile extension modules?

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

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

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.

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

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?


Asked by: Freddie864 | Posted: 01-10-2021






Answer 1

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

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

Answered by: Connie166 | Posted: 02-11-2021



Similar questions

bash extension modules on python

I know that it is possible to write bash extension modules (loadable builtins) on C or lua (see luabash), but is it possible on Python/Cython? Is there any projects that make steps in this direction?


bash extension modules on python

I know that it is possible to write bash extension modules (loadable builtins) on C or lua (see luabash), but is it possible on Python/Cython? Is there any projects that make steps in this direction?


Vim extension (via Python)?

is it possible to extend vim functionality via custom extension (preferably, written in Python)? What I need ideally is custom command when in command mode. E.g. ESC :do_this :do_that


How do I copy files with specific file extension to a folder in my python (version 2.5) script?

I'd like to copy the files that have a specific file extension to a new folder. I have an idea how to use os.walk but specifically how would I go about using that? I'm searching for the files with a specific file extension in only one folder (this folder has 2 subdirectories but the files I'm looking for will never be found in these 2 subdirectories so I don't need to search in these subdirectories). Thanks in...


python - Dynamic use of a class method defined in a Cython extension module

I would like to use the C implementation of a class method (generated from Cython) if it is present, or use its Python equivalent if the C extension is not present. I first tried this: class A(object): try: import c_ext method = c_ext.optimized_method except ImportError: def method(self): return "foo" ...


Python Extension Returned Object Etiquette

I am writing a python extension to provide access to Solaris kstat data ( in the same spirit as the shipping perl library Sun::Solaris::Kstat ) and I have a question about conditionally returning a list or a single object. The python use case would look something like: cpu_stats = cKstats.lookup(module='cpu_stat') cpu_stat0 = cKstats.lookup('cpu_stat',0,'cpu_stat0') As it's currently implemen...


Can I create a Python extension module in D (instead of C)

I hear D is link-compatible with C. I'd like to use D to create an extension module for Python. Am I overlooking some reason why it's never going to work?


python - Komodo Extension

Closed. This question does not meet Stack Overflow guid...


How to update an older C extension for Python 2.x to Python 3.x

I'm wanting to use an extension for Python that I found here, but I'm using Python 3.1 and when I attempt to compile the C extension included in the package (_wincon), it does not compile due to all the syntax errors. Unfortunately, it was written for 2.x versions of Python and as such includes methods such as PyMember_Get and


Count number of files with certain extension in Python

I am fairly new to Python and I am trying to figure out the most efficient way to count the number of .TIF files in a particular sub-directory. Doing some searching, I found one example (I have not tested), which claimed to count all of the files in a directory: file_count = sum((len(f) for _, _, f in os.walk(myPath))) This is fine, but I need to only count TIF files. My directory...


python - How create jinja2 extension?

I try to make extension for jinja2. I has written such code: http://dumpz.org/12996/ But I receive exception: 'NoneType' object is not iterable. Where is a bug? That should return parse. Also what should accept and return _media?


Making a C extension to Python that requires another extension

I have a couple of Python functions that I use to make game development with Pygame easier. I have them in a file called helper.py in my Python-path, so I can import them from any game I make. I thought, as an exercise to learn about Python extensions, to convert this module to C. My first problem is that I need to use functions from Pygame, and I'm not sure if this is possible. Pygame installs some header files, but they ...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top