Fix ccall return and close file