Subject: [FFC-dev] deleting ufc_form

From: Johan Hake <[email-masked]>
Date: Mon, 24 Nov 2008 21:39:45 +0100

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

---

From: Anders Logg <[email-masked]>
Date: Mon, 24 Nov 2008 22:02:43 +0100

> derived class produced by ffc.

Sounds good. Patches welcome. Will get started on applying your other patches.

-- 
Anders

---

From: Johan Hake <[email-masked]>
Date: Mon, 24 Nov 2008 22:15:48 +0100

On Monday 24 November 2008 22:02:43 Anders Logg wrote:
> > 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.
> >
> > 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.
> >

Well, I am not so into the code generation part of ffc, so I would have hoped 
you could have a look at it ;)

Btw, why isn't _ufc_form stored as a shared_ptr? It would make it a bit 
easier. 

Johan

---

From: Anders Logg <[email-masked]>
Date: Mon, 24 Nov 2008 22:38:49 +0100

> 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 

It wasn't needed at the time. I'll think about making it a shared
pointer.

-- 
Anders

---

From: "Garth N. Wells" <[email-masked]>
Date: Mon, 24 Nov 2008 22:22:39 +0000

> It wasn't needed at the time. I'll think about making it a shared

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.

Garth

> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> FFC-dev mailing list
> [email-masked]
> http://www.fenics.org/mailman/listinfo/ffc-dev

---

From: Johan Hake <[email-masked]>
Date: Mon, 24 Nov 2008 23:44:04 +0100

On Monday 24 November 2008 23:22:39 Garth N. Wells wrote:
> >>>> code to instantiate a dolfin::Form it does not take care of deleting
> >>>> the 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
> >>>
> >> Well, I am not so into the code generation part of ffc, so I would have
> >> hoped you could have a look at it ;)
> >

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