Fix leaks when pruning inferiors.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 1 Dec 2019 14:40:17 +0000 (15:40 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 5 Dec 2019 22:19:22 +0000 (23:19 +0100)
Valgrind detects various inferior related leaks, such as:
  ==31877== 5,530 (56 direct, 5,474 indirect) bytes in 1 blocks are definitely lost in loss record 7,131 of 7,355
  ==31877==    at 0x4C2E18C: calloc (vg_replace_malloc.c:760)
  ==31877==    by 0x23E580: xcalloc (alloc.c:100)
  ==31877==    by 0x4794A9: xcnewvec<void*> (poison.h:158)
  ==31877==    by 0x4794A9: registry_alloc_data(registry_data_registry*, registry_fields*) (registry.c:51)
  ==31877==    by 0x3A537C: inferior_alloc_data (inferior.c:43)
  ==31877==    by 0x3A537C: inferior::inferior(int) (inferior.c:92)
  ==31877==    by 0x3A5426: add_inferior_silent(int) (inferior.c:98)
  ==31877==    by 0x3A5530: add_inferior(int) (inferior.c:122)
  ...

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.

gdb/ChangeLog
2019-12-05  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
* inferior.c (prune_inferiors):  Only call delete_inferior.
Do not modify the inferior list.

gdb/ChangeLog
gdb/inferior.c

index c6f7909777b65938ddfa0b0836be39637f3ae64d..5e4b9f1b176247ef803585811b8075ee8aaa59de 100644 (file)
@@ -1,3 +1,7 @@
+2019-12-05  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+       * inferior.c (prune_inferiors):  Only call delete_inferior,
+       Do not modify the inferior list.
+
 2019-12-05  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * c-exp.y: Update calls to lookup_typename,
index 84e4d24e738b157a13b1e6d630e917c2e130128a..87df193ac392eef2fc2882c1681611057ddc6b07 100644 (file)
@@ -370,24 +370,22 @@ have_live_inferiors (void)
 void
 prune_inferiors (void)
 {
-  struct inferior *ss, **ss_link;
+  inferior *ss;
 
   ss = inferior_list;
-  ss_link = &inferior_list;
   while (ss)
     {
       if (!ss->deletable ()
          || !ss->removable
          || ss->pid != 0)
        {
-         ss_link = &ss->next;
-         ss = *ss_link;
+         ss = ss->next;
          continue;
        }
 
-      *ss_link = ss->next;
+      inferior *ss_next = ss->next;
       delete_inferior (ss);
-      ss = *ss_link;
+      ss = ss_next;
     }
 }
 
This page took 0.031606 seconds and 4 git commands to generate.