In gridlink_impl.c.src, the reallocation code uses my_realloc to increase the amount of memory by MEMORY_INCREASE_FAC, but will try again with smaller values if any of the reallocations fail:
So, if the x realloc succeeds, but y fails, the next iteration will try to realloc x, even though that pointer was invalidated by the first successful x realloc.
I think one solution would be to immediately assign successful reallocs to the original pointer and omit the free calls.
In gridlink_impl.c.src, the reallocation code uses
my_realloc
to increase the amount of memory byMEMORY_INCREASE_FAC
, but will try again with smaller values if any of the reallocations fail:However, if the
x
realloc succeeds andy
does not, I don't think it's valid to "try again" on the originalx
pointer. From the realloc docs:So, if the
x
realloc succeeds, buty
fails, the next iteration will try to reallocx
, even though that pointer was invalidated by the first successfulx
realloc.I think one solution would be to immediately assign successful reallocs to the original pointer and omit the
free
calls.