https://gcc.gnu.org/g:9543cac89c8847bf51a13665ca795c278dd4ffa3

commit r17-5091-g9543cac89c8847bf51a13665ca795c278dd4ffa3
Author: Jørgen Kvalsvik <[email protected]>
Date:   Mon Oct 12 15:28:04 2026 +0200

    Fix memory leak, call free_graph
    
    I happened to notice a memory leak and confirmed with valgrind:
    
    65,640 (104 direct, 65,536 indirect) bytes in 1 blocks are definitely lost 
in loss record 530 of 532
       at 0x4844818: malloc (vg_replace_malloc.c:446)
       by 0x2C0DDBB: xmalloc (xmalloc.c:149)
       by 0xF22F49: new_graph(int) (graphds.cc:52)
       by 0x285F030: cfg_as_graph (path-coverage.cc:71)
       ...
    
    Maybe amusingly, I specifically documented that cfg_as_graph have to
    call free_graph on the returned pointer.
    
    gcc/ChangeLog:
    
            * path-coverage.cc (find_prime_paths): Call free_graph.

Diff:
---
 gcc/path-coverage.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/path-coverage.cc b/gcc/path-coverage.cc
index b9c25e3b3d92..6256e6cb8752 100644
--- a/gcc/path-coverage.cc
+++ b/gcc/path-coverage.cc
@@ -134,6 +134,7 @@ find_prime_paths (struct function *fn)
   if (any_empty)
     VEC_ORDERED_REMOVE_IF (paths, ix1, ix2, ptr, ptr->is_empty ());
 
+  free_graph (cfg);
   return paths;
 }

Reply via email to