public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "franke dot daniel at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/29101] New: memory leak in libgfortran Date: Fri, 15 Sep 2006 19:59:00 -0000 [thread overview] Message-ID: <bug-29101-6552@http.gcc.gnu.org/bugzilla/> (raw) Please find below a stripped down testcase and a session log from valgrind. The code reads input from stdin, compares what was read against a couple of choices (exactly one in this case) and repeats reading until a single 'x' was entered. The leak is related to the length of the input buffer within the main program, hitting [enter] N times before giving an 'x' results in N leaked blocks of strlen(input). Also involved is the SELECT CASE: if it is replaced by an equivalent IF-statement, no memory is leaked. Reproducible with gfortran-4.1.1 and gfortran-4.2 20060914 (experimental). $> cat test.f90 MODULE stringutils CHARACTER(*), PRIVATE, PARAMETER :: lowercase = 'abcdefghijklmnopqrstuvwxyz' CHARACTER(*), PRIVATE, PARAMETER :: uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' CONTAINS FUNCTION tolower(instr) RESULT (outstr) CHARACTER(len=*), INTENT(in) :: instr CHARACTER(len=len(instr)) :: outstr INTEGER :: i, k outstr = instr DO i = 1, len_trim(outstr) k = index(uppercase, outstr(i:i)) if (k /= 0) outstr(i:i) = lowercase(k:k) END DO END FUNCTION END MODULE MODULE configuration CONTAINS LOGICAL FUNCTION validate_value(input, value) USE stringutils CHARACTER(len=*), INTENT(in) :: input INTEGER, INTENT(out) :: value validate_value = .TRUE. SELECT CASE (tolower(input)) CASE ("x"); value = 1 CASE DEFAULT validate_value = .FALSE. END SELECT END FUNCTION END MODULE PROGRAM test USE configuration USE stringutils INTEGER :: value CHARACTER(len=256) :: input DO WRITE (*, FMT="(A)", ADVANCE = "NO") "$> " READ (*, FMT="(A)") input IF (validate_value(input, value)) EXIT END DO END PROGRAM $> gfortran-4.2 -g -Wall test.f90 $> valgrind --tool=memcheck --leak-check=full ./a.out ==9829== Memcheck, a memory error detector. ==9829== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al. ==9829== Using LibVEX rev 1606, a library for dynamic binary translation. ==9829== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP. ==9829== Using valgrind-3.2.0, a dynamic binary instrumentation framework. ==9829== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al. ==9829== For more details, rerun with: -v ==9829== %> %> %> %> %> %> x ==9829== ==9829== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 1) ==9829== malloc/free: in use at exit: 1,536 bytes in 6 blocks. ==9829== malloc/free: 24 allocs, 18 frees, 55,080 bytes allocated. ==9829== For counts of detected errors, rerun with: -v ==9829== searching for pointers to 6 not-freed blocks. ==9829== checked 78,156 bytes. ==9829== ==9829== 1,536 bytes in 6 blocks are definitely lost in loss record 1 of 1 ==9829== at 0x4021396: malloc (vg_replace_malloc.c:149) ==9829== by 0x40304EC: _gfortrani_get_mem (memory.c:53) ==9829== by 0x80488FA: __configuration__validate_value (dump.f90:29) ==9829== by 0x8048A9A: MAIN__ (dump.f90:47) ==9829== by 0x8048AD6: main (fmain.c:18) ==9829== ==9829== LEAK SUMMARY: ==9829== definitely lost: 1,536 bytes in 6 blocks. ==9829== possibly lost: 0 bytes in 0 blocks. ==9829== still reachable: 0 bytes in 0 blocks. ==9829== suppressed: 0 bytes in 0 blocks. ==9829== Reachable blocks (those to which a pointer was found) are not shown. ==9829== To see them, rerun with: --show-reachable=yes -- Summary: memory leak in libgfortran Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: franke dot daniel at gmail dot com GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29101
next reply other threads:[~2006-09-15 19:59 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-09-15 19:59 franke dot daniel at gmail dot com [this message] 2006-09-16 1:29 ` [Bug libfortran/29101] " jvdelisle at gcc dot gnu dot org 2006-09-17 20:14 ` [Bug fortran/29101] Memory leak in gfortran jvdelisle at gcc dot gnu dot org 2006-09-18 6:53 ` pault at gcc dot gnu dot org 2006-09-18 7:50 ` pault at gcc dot gnu dot org 2006-09-18 17:15 ` patchapp at dberlin dot org 2006-09-18 19:29 ` pault at gcc dot gnu dot org 2006-09-18 20:20 ` pault at gcc dot gnu dot org 2006-09-18 22:24 ` pault at gcc dot gnu dot org 2006-09-18 22:35 ` steven at gcc dot gnu dot org 2006-09-19 11:05 ` pault at gcc dot gnu dot org 2006-09-19 11:25 ` pault at gcc dot gnu dot org 2006-09-19 11:26 ` pault at gcc dot gnu dot org 2006-09-19 11:56 ` paulthomas2 at wanadoo dot fr
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-29101-6552@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).