This is the expected behaviour in case realloc cannot allocate the needed space or in case requested size is 0. I suggest you to place a breakpoint on realloc line ans examine the value of 'i': if it's -1 resulting size will be 0 and the allocated memory pointed to by separatedVal will be freed.