This is the mail archive of the gcc-patches@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]

[PATCH] Fix leak in gcse-after-reload


I noticed this leak while looking for leaks on the tree-ssa.
Basically in eliminate_partially_redundant_loads, the memory
that was allocated was not freed at all.

Mostafa since this is code which you added is this okay with you?

OK to commit? Bootstrapped on powerpc-apple-darwin and i686-pc-linux-gnu
with no regressions.

Thanks,
Andrew Pinski

ChangeLog:

* gcse.c (eliminate_partially_redundant_loads): Instead of returning early,
goto a cleanup label. After the cleanup, free the allocated memory.


Patch:
Index: gcse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcse.c,v
retrieving revision 1.205.2.38
diff -u -p -r1.205.2.38 gcse.c
--- gcse.c	29 Apr 2004 19:44:29 -0000	1.205.2.38
+++ gcse.c	10 May 2004 04:10:20 -0000
@@ -8398,14 +8398,14 @@ eliminate_partially_redundant_loads (bas

if (npred_ok == 0 /* No load can be replaced by copy. */
|| (optimize_size && npred_ok > 1)) /* Prevent exploding the code. */
- return;
+ goto cleanup;


/* Check if it's worth applying the partial redundancy elimination. */
if (ok_count < GCSE_AFTER_RELOAD_PARTIAL_FRACTION * not_ok_count)
- return;
+ goto cleanup;


   if (ok_count < GCSE_AFTER_RELOAD_CRITICAL_FRACTION * critical_count)
-    return;
+    goto cleanup;

   /* Generate moves to the loaded register from where
      the memory is available.  */
@@ -8458,6 +8458,22 @@ eliminate_partially_redundant_loads (bas
     delete_insn (insn);
   else
     a_occr->deleted_p = 1;
+
+cleanup:
+
+  while (unavail_occrs)
+    {
+      struct unoccr *temp = unavail_occrs->next;
+      free (unavail_occrs);
+      unavail_occrs = temp;
+    }
+
+  while (avail_occrs)
+    {
+      struct unoccr *temp = avail_occrs->next;
+      free (avail_occrs);
+      avail_occrs = temp;
+    }
 }

/* Performing the redundancy elimination as described before. */

Attachment: leaksgcse.diff.txt
Description: Text document


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