Re: [eigen] Memory Leak When Constructor of User-Defined Type Throws Exception

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On 06.07.2014 07:47, Moritz Klammler wrote:
unfortunately, the Bugzilla server is not functional (I don't know for
how long this might be) so I could not check whether this issue has
already been reported.

This appears to be related to a software update by http://tuxfamily.org/
Jitse is currently investigating.

Currently, if the constructor of a (user-defined) type throws an
exception during construction of a dense matrix with dynamic size, the
memory for the storage of the (not created) matrix is leaked.  This is
not a documented [1] limitation for user-defined types so I assume that
it is not intended behavior.  (The page also does not mention that
user-defined types must be default-constructible.  Although, that might
go without saying.)

Yes, we shall make Eigen leak-proof wherever possible. And we could add a note to [1] that types must be default-constructible.

I'm confident that modern compilers are smart enough to optimize away the try-catch block if the Scalar constructor does not throw, however we need to #ifdef-guard it for platforms which do not support exceptions. For that we already have:
  #ifdef EIGEN_EXCEPTIONS


Attached is a unit test that demonstrates the leak if run through
Valgrind (or some other debugger) as in

It would be nice to have a proper unit-test that actually checks if everything gets deconstucted properly, maybe by keeping track of allocations in a static variable. (Also, your unit test will wrongfully assert with a probability of (10/11)^1288 *g* )


Christoph

[1] http://eigen.tuxfamily.org/dox/TopicCustomizingEigen.html#user_defined_scalars


--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252
----------------------------------------------



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/