Errors related to free_ivector


jdpicka
09-16-2005, 03:20 PM
I am getting segmentation faults when using various combinations of the commands

dmatrix/free_dmatrix
dvector/free_dvector
ivector/free_ivector

The C program (running in RedHat 9) will execute properly but the segfaults when it it gets part of the way through the free-ing routines at the end. It will typically run several free-ing routines successfully before stopping part way through the list at what gdb identifies as:

Program received signal SIGSEGV, Segmentation fault.
0x420748e0 in _int_free () from /lib/tls/libc.so.6

Googling suggests that this can be caused by trying to free something twice, but that isn't happening in any obvious way. What is odd is the way that it will execute the free-ing routine on one vector, then fail on another of exactly the same type and size.

The program that crashes is attached. It crashes on my machine after free-ing rj.

Saul Teukolsky
09-16-2005, 07:51 PM
Hi,

You have out-of-bounds accesses to your arrays. dvector and dmatrix
create arrays with valid subscript ranges equal to their arguments.
Your for loops go 1 too far.

The NR code is fine.

Best wishes,
Saul Teukolsky

jdpicka
09-17-2005, 05:35 PM
Many thanks for pointing out my CS 100-level error. I possibly should not try debugging programs late on a Friday afternoon without extra coffee.