Fixed mem leak if realloc fails