fix memory leaks in source=file; better error handling