[Nix-dev] GCC 5, Matplotlib, and tcmalloc don't work together

Andreas Herrmann andreash87 at gmx.ch
Wed Jun 1 11:30:05 CEST 2016


Hi,

I'm writing this in case anyone else encounters a similar issue.

I have a C++ library that is primarily used by C++ executables, but is also used by a Python package. I noticed that ever since the update of nixpkgs to GCC 5 (determined by git bisect) Python would crash if I first imported matplotlib.pylab (with any of the Qt backends) and then my own C++ module. If I imported them in the opposite order then no error would occur.
(The error message was: `src/tcmalloc.cc:278] Attempt to free invalid pointer 0x154b870`)

The C++ module was using tcmalloc from gperftools [1]. Today I found out, that the Python issue goes away if I do not use tcmalloc but instead just standard glibc malloc for the C++ module.

Previously I was explicitly using GCC 5 for the C++ module, but was using the Python 2.7 stack that came with nixpkgs, presumably compiled with GCC 4.9. In that configuration tcmalloc was not causing any issues.

I'm not opening an issue on github about this because I don't have any short example code that I can share to reproduce the issue. Also, I don't know if there is anything to fix about this. Maybe it's just a bad idea to mix allocators and I was lucky before. Let me know if you think it deserves an issue anyway.

The C++ library is made available to Python using pybind11 v1.7 [2]. All this was happening on 64 bit Linux.

Best, Andreas

[1]: http://goog-perftools.sourceforge.net/doc/tcmalloc.html
[2]: https://github.com/pybind/pybind11


More information about the nix-dev mailing list