fix: leaking tmp files in erroneous cases