Fix realloc/free stuffs