The warning by GCC is false positive because we don't access the freed memory in the scope, only the pointer memory which contained address of allocated memory on the heap, and used that for updating index pointer.
Using ptrdiff_t struct before realloc works the warning around.