[RFA] Fix leaks by clearing registers and frame caches.

Philippe Waroquiers philippe.waroquiers@skynet.be
Sat May 4 05:51:00 GMT 2019


On Thu, 2019-05-02 at 18:32 -0700, Kevin Buettner wrote:
> Philippe Waroquiers <philippe.waroquiers@skynet.be> wrote:
> 
> > diff --git a/gdb/corelow.c b/gdb/corelow.c
> > index 3ce612d31b..9fcc2d2372 100644
> > --- a/gdb/corelow.c
> > +++ b/gdb/corelow.c
> > @@ -535,6 +535,8 @@ core_target::detach (inferior *inf, int from_tty)
> >       'this'.  */
> >    unpush_target (this);
> >  
> > +  /* Clear the register cache and the frame cache.  */
> > +  registers_changed ();
> 
> I'm wondering if it might be better to call
> 
>   registers_changed_ptid (ptid_t (inf->pid));
> 
> instead?  (I haven't checked to see if this compiles, but hopefully you get
> the idea.)
> 
> That way, we only touch the register cache for the inferior being
> detached.
Yes, I contemplated doing that.
But the detach code is somewhat tricky, as it is not clear up to
what point the 'inf' and/or inf->pid stays valid + the detach
method is target dependent and can do whatever.
(see e.g. the comment about the 'this' that becomes dangling).

So, it looked safer to me to just clear the register and framecache
when an inferior exits and/or detach, as the efficiency for such
operation is not critical (and there are already many places that
are doing that when attaching/detaching/forking/...).


> 
> >    reinit_frame_cache ();
> >    maybe_say_no_core_file_now (from_tty);
> >  }
> > diff --git a/gdb/inferior.c b/gdb/inferior.c
> > index e7b49376e9..abfef700c3 100644
> > --- a/gdb/inferior.c
> > +++ b/gdb/inferior.c
> > @@ -208,6 +208,10 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
> >    inf->pending_detach = 0;
> >    /* Reset it.  */
> >    inf->control = inferior_control_state (NO_STOP_QUIETLY);
> > +
> > +  /* Clear the register cache and the frame cache.  */
> > +  registers_changed ();
> 
> Likewise here.
> 
> > +  reinit_frame_cache ();
> >  }
> 
> It seems okay to me otherwise...
Thanks for the review, I haved pushed the fix with the 'global clear'
(for the reasons explained above) but if there is a need to
have a more 'precise clear', just tell me, and I can rework this
in a follow up.

Philippe
 



More information about the Gdb-patches mailing list