TEOS-10/GSW-Python

memory leak - geo_strf_dyn_height

ocehugo opened this issue · 4 comments

Hello,

Facing interpreter crash with a malloc error/overflow.

from gsw import geo_strf_dyn_height
k=20
x = geo_strf_dyn_height(np.zeros(k)+34,np.zeros(k)+12,np.linspace(1,10,k))
print(x[-1])

Behaviour on my OSX: Sometimes x =(-0.22), sometimes x=nan, sometimes a total crash of the interpreter:

Python(69006,0x10096d3c0) malloc: *** error for object 0x7fcc987375f0: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug

Behaviour on a different machine (linux): Totally fine with k<=20. But if k, the pressure interval, is increased - say 60 I got a backtrace:

*** glibc detected ***  malloc(): memory corruption: 0x0000000002a20e00 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3771a75dee]
/lib64/libc.so.6[0x3771a7a3aa]
/lib64/libc.so.6(__libc_malloc+0x5c)[0x3771a7aaac]
.../gsw/_gsw_ufuncs.cpython-35m-x86_64-linux-gnu.so(gsw_geo_strf_dyn_height+0x386)[0x7f53981f6c86]
.../gsw/_gsw_ufuncs.cpython-35m-x86_64-linux-gnu.so(+0x6fee)[0x7f53981d4fee]
.../lib/libpython3.5m.so.1.0(PyCFunction_Call+0xc9)[0x7f53a7a81c49]

Python versions are different between machines (3.6.2 vs 3.5), and packages are installed differently (one is from homebrew vs anaconda) . So appears to be a error in the gsw package and it's sources.

I also compiled the GSW extensions with gcc on my OSX:
CC=gcc-7 CFLAGS="-O0 -g -Wall" pip install -I gsw
but results were unchange.

So some pointers in gsw_ufuncs or gsw-c source are wrong!?

Thanks for the good test case. I can confirm this on my OSX installation also. I will try to work on this tomorrow, starting with some updates from GSW-C.

So far, testing indicates that the failure is restricted to the case where p_ref < p_min.

There appear to be major problems even in the latest C code; once they are straightened out, I will port the C over and see if that takes care of everything here.

Closed by #24