← Back to team overview

ffc team mailing list archive

Re: deleting ufc_form

 

On Monday 24 November 2008 23:22:39 Garth N. Wells wrote:
> Anders Logg wrote:
> > On Mon, Nov 24, 2008 at 10:15:48PM +0100, Johan Hake wrote:
> >> On Monday 24 November 2008 22:02:43 Anders Logg wrote:
> >>> On Mon, Nov 24, 2008 at 09:39:45PM +0100, Johan Hake wrote:
> >>>> Hello!
> >>>>
> >>>> While working on the python interface of dolfin I come over a memory
> >>>> corruption in the dolfin::Form destructor. While ffc -ldolfin produce
> >>>> code to instantiate a dolfin::Form it does not take care of deleting
> >>>> the ufc_form.
> >>>>
> >>>> In the destrutor of the base class Form there is a
> >>>>
> >>>>   delete _ufc_form;
> >>>>
> >>>> I do not know if this while prevent any memory leak from the ffc
> >>>> produced code, e.g., if the base class destructor is not calle or
> >>>> something, but that line _will_ corrupt any try to instantiate a
> >>>> dolfin::Form directly using an ufc_form, which we have to do in
> >>>> PyDOLFIN.
> >>>>
> >>>> My suggestion is to remove the above mentioned line from
> >>>> dolfin::~Form(), which I have done locally, and add the same line in
> >>>> the destructor of the derived class produced by ffc.
> >>>>
> >>>> Any comment?
> >>>>
> >>>> Johan
> >>>
> >>> Sounds good. Patches welcome. Will get started on applying your other
> >>> patches.
> >>
> >> Well, I am not so into the code generation part of ffc, so I would have
> >> hoped you could have a look at it ;)
> >
> > Sure, it's an easy fix (in dolfinformat.py). I will fix it as soon as
> > I get a chance.
> >
> >> Btw, why isn't _ufc_form stored as a shared_ptr? It would make it a bit
> >> easier.
> >
> > It wasn't needed at the time. I'll think about making it a shared
> > pointer.
>
> Making it a shared_ptr would be the best option. dolfin::Form should
> have a constructor that accepts a shared_ptr to a ufc::form. My problem
> with delete in the generated code and removing it from Form is that a
> pointer to a ufc::form appears in Form, but no matching delete. We
> shouldn't rely on the derived class to clean up the base class.

Ok, then I can change it to shared_ptr, and Anders have to change ffc for 
the -ldolfin generated code.

Btw, in a few minutes we can assemble in python again!

Johan


References