Bug 108924 - memory leak in doloop_warn
Summary: memory leak in doloop_warn
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: anlauf
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-24 12:31 UTC by Richard Biener
Modified: 2023-03-03 14:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-02-24 00:00:00


Attachments
Tentative patch (256 bytes, patch)
2023-02-24 16:37 UTC, anlauf
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2023-02-24 12:31:42 UTC
valgrind leak check complains

==8747== 16 bytes in 2 blocks are definitely lost in loss record 6 of 2,309
==8747==    at 0x4C346A4: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8747==    by 0x5697698: __gmp_default_allocate (in /usr/lib64/libgmp.so.10.3.2)
==8747==    by 0x56A7A22: __gmpz_init_set (in /usr/lib64/libgmp.so.10.3.2)
==8747==    by 0x874110: do_subscript (frontend-passes.cc:2863)
==8747==    by 0x874110: do_function(gfc_expr**, int*, void*) (frontend-passes.cc:2710)
==8747==    by 0x870675: gfc_expr_walker(gfc_expr**, int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5243)
==8747==    by 0x870859: gfc_expr_walker(gfc_expr**, int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5250)
==8747==    by 0x870859: gfc_expr_walker(gfc_expr**, int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5250)
==8747==    by 0x8727D9: gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5680)
==8747==    by 0x872857: gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5687)
==8747==    by 0x872857: gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5687)
==8747==    by 0x872857: gfc_code_walker(gfc_code**, int (*)(gfc_code**, int*, void*), int (*)(gfc_expr**, int*, void*), void*) (frontend-passes.cc:5687)
==8747==    by 0x8738CB: doloop_warn(gfc_namespace*) (frontend-passes.cc:3079)

so it looks like some gmp vars are not released.
Comment 1 anlauf 2023-02-24 16:37:29 UTC
Created attachment 54532 [details]
Tentative patch

Does the attached fix this?  Without a testcase this seems to be the fix
obtained from reviewing the surrounding code.  Regtests cleanly here.
Comment 2 GCC Commits 2023-02-24 20:30:58 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:45f406c4f62e516b58dcda20b5a7aa43ff0aa0f3

commit r13-6336-g45f406c4f62e516b58dcda20b5a7aa43ff0aa0f3
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Feb 24 19:56:32 2023 +0100

    Fortran: frontend passes do_subscript leaks gmp memory [PR108924]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108924
            * frontend-passes.cc (do_subscript): Clear used gmp variable.
Comment 3 anlauf 2023-02-24 20:39:59 UTC
Taken.  Waiting on feedback.
Comment 4 Richard Biener 2023-03-03 14:04:26 UTC
Building the benchmark set fprate_any_fortran of SPEC CPU 2017 there's no leak
from an allocation in do_subscript or do_function anymore.