[RFA] Fix leaks when pruning inferiors.

Pedro Alves palves@redhat.com
Thu Dec 5 16:42:00 GMT 2019


On 12/1/19 3:52 PM, Philippe Waroquiers wrote:

> Origin of the leaks is in prune_inferiors: prune_inferiors is first removing
> the inferior to prune from the inferior list, then calls delete_inferior.
> But delete_inferior will only really destroy the inferior when it finds
> it into the inferior list.
> As delete_inferior is removing the inferior to delete from the inferior list,
> ensure prune_inferiors only calls delete_inferior, without touching the
> inferior list.

Whoops.

> @@ -370,24 +370,22 @@ have_live_inferiors (void)
>  void
>  prune_inferiors (void)
>  {
> -  struct inferior *ss, **ss_link;
> +  struct inferior *ss, *ss_next;
>  

>  
> -      *ss_link = ss->next;
> +      ss_next = ss->next;
>        delete_inferior (ss);
> -      ss = *ss_link;
> +      ss = ss_next;

Please declare ss_next here instead of at the top.
You can omit the redundant "struct" while at it:

      inferior *next = ss->next;
      delete_inferior (ss);
      ss = next;

OK with that change.  Thanks!

Pedro Alves



More information about the Gdb-patches mailing list