This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/80477] [OOP] Polymorphic function result generates memory leak


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);
        }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]