osx_write.c: Use realloc() instead of free() and malloc()