Fix use after free on file received