Home My Page Projects MPFI
Summary Activity Forums Tracker Lists Tasks Docs News SCM Files

[#21669] Memory leak in mpfi_const_pi

Date:
2018-05-23 12:33
Priority:
3
State:
Open
Submitted by:
Joris Picot (jpicot)
Assigned to:
Nobody (None)
Category:
none
Group:
none
Resolution:
none
Summary:
Memory leak in mpfi_const_pi

Detailed description
Using valgrind for my programs, I fond a leak in function mpfi_const_pi. Here is an elemental code

#include <mpfi.h>
int main()
{
mpfi_t p;
mpfi_init (p);
mpfi_const_pi (p);
mpfi_clear (p);
return 0;
}

that I put into main.c (see attached file), and I compiled it with the command-line

gcc -g -Wall -Wextra -O0 -ansi -pedantic -std=c11 main.c -o main -lmpfi

When run with

valgrind --leak-check=full --show-leak-kinds=all ./main

I get

==20680== Memcheck, a memory error detector
==20680== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20680== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==20680== Command: ./main
==20680==
==20680==
==20680== HEAP SUMMARY:
==20680== in use at exit: 16 bytes in 1 blocks
==20680== total heap usage: 3 allocs, 2 frees, 48 bytes allocated
==20680==
==20680== 16 bytes in 1 blocks are still reachable in loss record 1 of 1
==20680== at 0x4C2CEDF: malloc (vg_replace_malloc.c:299)
==20680== by 0x5698898: __gmp_default_allocate (in /usr/lib/libgmp.so.10.3.2)
==20680== by 0x5421510: mpfr_allocate_func (in /usr/lib/libmpfr.so.6.0.1)
==20680== by 0x541EF2E: mpfr_init2 (in /usr/lib/libmpfr.so.6.0.1)
==20680== by 0x5451E1B: mpfr_cache (in /usr/lib/libmpfr.so.6.0.1)
==20680== by 0x4E400EE: mpfi_const_pi (in /usr/lib/libmpfi.so.0.0.0)
==20680== by 0x108813: main (main.c:10)
==20680==
==20680== LEAK SUMMARY:
==20680== definitely lost: 0 bytes in 0 blocks
==20680== indirectly lost: 0 bytes in 0 blocks
==20680== possibly lost: 0 bytes in 0 blocks
==20680== still reachable: 16 bytes in 1 blocks
==20680== of which reachable via heuristic:
==20680== newarray : 16 bytes in 1 blocks
==20680== suppressed: 0 bytes in 0 blocks
==20680==
==20680== For counts of detected and suppressed errors, rerun with: -v
==20680== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Message  ↓
Date: 2018-05-28 09:19
Sender: Joris Picot

After a little peek in MPFI source code, I discovered that MPFI just calls mpfr_const_pi. So I run the code:

#include <mpfr.h>
int main ()
{
mpfr_t a;
mpfr_init (a);
mpfr_const_pi(a, MPFR_RNDN);
mpfr_clear (a);
return 0;
}

using the same compilation options. Valgrind basically give me the same error summary:

==15014== Memcheck, a memory error detector
==15014== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==15014== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==15014== Command: ./main
==15014==
==15014==
==15014== HEAP SUMMARY:
==15014== in use at exit: 16 bytes in 1 blocks
==15014== total heap usage: 2 allocs, 1 frees, 32 bytes allocated
==15014==
==15014== 16 bytes in 1 blocks are still reachable in loss record 1 of 1
==15014== at 0x4C2CEDF: malloc (vg_replace_malloc.c:299)
==15014== by 0x5481898: __gmp_default_allocate (in /usr/lib/libgmp.so.10.3.2)
==15014== by 0x4E4E510: mpfr_allocate_func (in /usr/lib/libmpfr.so.6.0.1)
==15014== by 0x4E4BF2E: mpfr_init2 (in /usr/lib/libmpfr.so.6.0.1)
==15014== by 0x4E7EE1B: mpfr_cache (in /usr/lib/libmpfr.so.6.0.1)
==15014== by 0x108818: main (main.c:10)
==15014==
==15014== LEAK SUMMARY:
==15014== definitely lost: 0 bytes in 0 blocks
==15014== indirectly lost: 0 bytes in 0 blocks
==15014== possibly lost: 0 bytes in 0 blocks
==15014== still reachable: 16 bytes in 1 blocks
==15014== of which reachable via heuristic:
==15014== newarray : 16 bytes in 1 blocks
==15014== suppressed: 0 bytes in 0 blocks
==15014==
==15014== For counts of detected and suppressed errors, rerun with: -v
==15014== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Attachments:
Size Name Date By Download
125 bytesmain.c2018-05-23 12:33jpicotmain.c
Field Old Value Date By
File Added6115: main.c2018-05-23 12:33jpicot