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

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


On 19.07.2014 00:00, Moritz Klammler wrote:
thank you for looking at the patch and sorry for my late reply.  I have
(finally) applied your suggestions now (see attached).

Yes, at first glance all looks good. I think this evening I have a deeper look and push it to the dev-branch.

The unit test is now using a static object count as suggested.  However,
this can only check that the member-wise destruction happens.  I don't
know of a way to check from within C++ that a 'std::malloc()'ed pointer
was 'std::free()'ed again.  (Eigen does not use operator 'new' /
'delete' to manage the storage array.)

I found that ctest is actually able to run tests through valgrind. I failed to set this up so far, but it would certainly be nice in general.

While adding '#ifdef EIGEN_EXCEPTIONS' to the code, I found that there
is an existing try-catch in 'Memory.h' that is not surrounded by such
guards.  I've left it unchanged since it has nothing to do with the
reason for this patch.

I didn't spot any. There is only one try-catch block which is entirely inside an #ifdef EIGEN_EXCEPTIONS, because it is inside a macro.

[...] Then, we can write the above code as

     EIGEN_TRY
       {
         do_stuff();
         if (bad_things_happened())
           EIGEN_THROW(Ball("oh no!"));
       }
     EIGEN_CATCH(const Ball&)
       {
         do_other_stuff();
       }

Yes, that looks somewhat cleaner. We don't have a lot of try-catch blocks, so maybe it's not really worth the effort.

(off-topic: `throw Ball` always reminds me of http://xkcd.com/1188/)

Christoph


--
----------------------------------------------
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/