About ‘free(): invalid next size (fast)’ or 'double free or corruption (out)

When I try to run a python scripts, it will have this error:

double free or corruption (out)

And I try to use gdb to find out the problem, and it shows that

(gdb) where
#0 __GI_raise (sig=sig@entry=6) at …/sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7c57859 in __GI_abort () at abort.c:79
#2 0x00007ffff7cc226e in __libc_message (action=action@entry=do_abort,
fmt=fmt@entry=0x7ffff7dec298 “%s\n”) at …/sysdeps/posix/libc_fatal.c:155
#3 0x00007ffff7cca2fc in malloc_printerr (
str=str@entry=0x7ffff7dee670 “double free or corruption (out)”)
at malloc.c:5347
#4 0x00007ffff7ccbfa0 in _int_free (av=0x7ffff7e21b80 <main_arena>,
p=0x55555b41f0b0, have_lock=) at malloc.c:4314
#5 0x00007fffc7a3c4de in gmtlib_free_vector_ptr ()
from /home/ustc/anaconda3/envs/SWS/lib/libgmt.so
#6 0x00007fffc79c4b31 in gmtapi_destroy_data_ptr ()
from /home/ustc/anaconda3/envs/SWS/lib/libgmt.so
#7 0x00007fffc79d360b in gmtlib_garbage_collection ()
from /home/ustc/anaconda3/envs/SWS/lib/libgmt.so
#8 0x00007fffc79d3949 in GMT_Destroy_Session ()
from /home/ustc/anaconda3/envs/SWS/lib/libgmt.so
#9 0x00007ffff6dd3052 in ffi_call_unix64 ()

In the stack trace, it can be observed that the free function is called within the gmtlib_free_vector_ptr function, and it appears to occur during the destruction of a GMT object.

How to avoid this issue? Is this problem caused by my computer itself or by PyGMT?

It’s more likely an upstream GMT bug. Please post a minimum example so that we can reproduce the issue.