flintlib / arb

Arb has been merged into FLINT -- use https://github.com/flintlib/flint/ instead
http://arblib.org/
GNU Lesser General Public License v2.1
455 stars 137 forks source link

Memory leak for arb_hypergeom_coulomb #427

Closed MacroUniverse closed 2 years ago

MacroUniverse commented 2 years ago

Hi, after I turned on address sanitizer for g++, the runtime reported a memory leak after program exit if I call the Coulomb function:

#include <iostream>
#include "arb_hypgeom.h"

double arb_coulombF(double l, double eta, double x)
{
    slong prec = 80;
    double F = 0;
    arb_t l1, eta1, x1, F1;
    arb_init(l1); arb_init(eta1); arb_init(x1); arb_init(F1);
    arb_set_d(l1, l); arb_set_d(eta1, eta); arb_set_d(x1, x);
    int digits;
    arb_hypgeom_coulomb(F1, NULL, l1, eta1, x1, prec);
    arb_clear(l1); arb_clear(eta1); arb_clear(x1); arb_clear(F1);
    return F;
}

int main()
{
    arb_coulombF(2,-1.2,3.1);
}

compilation: g++ test.cpp -fsanitize=address -static-libasan -g -larb

Is this a bug or am I using it wrong?

MacroUniverse commented 2 years ago

================================================================= ==2310==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 448 byte(s) in 28 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)

Direct leak of 32 byte(s) in 2 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0xfffffffffffffe2f  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x1640aef2  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x221173cc  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x62f90c73  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x802a55b7ff  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x185621e97ffff  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x7bef57c443f8caff  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0xffffffffffffff66  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0xffffffffffffff70  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x1953bb8  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x371580a8ff  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x9e267497ffff  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0x572cda11ffffff  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0xf47abc4  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0xffffffffffffff7e  (<unknown module>)

Direct leak of 16 byte(s) in 1 object(s) allocated from:

0 0x7f8ad0ec5f00 in __interceptor_malloc (/mnt/c/Users/addis/Desktop/a.out+0xc5f00)

#1 0x7f8aceba9678 in flint_malloc (/usr/lib/libflint-2.5.2.so+0x39678)
#2 0xf4e6437bffffff  (<unknown module>)

Indirect leak of 2984 byte(s) in 45 object(s) allocated from:

0 0x7f8ad0ec62f0 in realloc (/mnt/c/Users/addis/Desktop/a.out+0xc62f0)

#1 0x7f8ace6696e3 in __gmp_default_reallocate (/usr/lib/x86_64-linux-gnu/libgmp.so.10+0x96e3)

SUMMARY: AddressSanitizer: 3704 byte(s) leaked in 90 allocation(s).

fredrik-johansson commented 2 years ago

Try calling flint_cleanup_master() before the program exits.

MacroUniverse commented 2 years ago

Try calling flint_cleanup_master() before the program exits.

Thanks, but it seems that the linker couldn't find this function. I used flint_cleanup() instead and it solved my problem.