This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/80477] [OOP] Polymorphic function result generates memory leak
- From: "janus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 06 May 2017 12:33:21 +0000
- Subject: [Bug fortran/80477] [OOP] Polymorphic function result generates memory leak
- Auto-submitted: auto-generated
- References: <bug-80477-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80477
--- Comment #20 from janus at gcc dot gnu.org ---
(In reply to janus from comment #19)
> And IIRC we even use the finalization
> wrapper for deallocating polymorphic variables in other cases (even if they
> have no actual FINAL procedures).
In fact the finalization wrapper itself does not take care of deallocating the
variable (since finalization also applies to non-allocatable variables), but it
does deallocate any allocatable components (if existent).
Plus: For any polymorphic variable, we need to check at *runtime* whether
finalization is necessary, since an extended type may have finalizers, even if
the base class does not.
The typical code that is generated for the deallocation of a polymorphic
variable 'c' looks like this:
if (c._data != 0B)
{
if (c._vptr->_final != 0B)
{
{
struct array0_t desc.0;
desc.0.dtype = 40;
desc.0.data = (void * restrict) c._data;
c._vptr->_final (&desc.0, c._vptr->_size, 0);
}
}
__builtin_free ((void *) c._data);
}