Fix the error of realloc() and add some missing files