agardiner / csv-diff

Performs field-by-field diffs of CSV files
BSD 2-Clause "Simplified" License
45 stars 18 forks source link

CSV.open call in csv_source.rb is leaking file handle #9

Closed NickDiMucci closed 5 years ago

NickDiMucci commented 5 years ago

https://github.com/agardiner/csv-diff/blob/abff443e856e9d88f711a4d6bcc688c8c6ab7139/lib/csv-diff/csv_source.rb#L107

CSV.open has a design flaw where the underlying file handle gets lost if you chain a call after it. This is an issue if you need to, for one example, delete the file used as the source after you are done diffing/parsing/etc. The CSV class doesn't let go of the handle and you can't get it back.

I have opened a PR to fix this.

https://github.com/agardiner/csv-diff/pull/8

To reproduce the issue, simply call CSVDiff.new with two files and then try to call File.delete on them.

And for context, I have a use case where I download two, third party CSV reports, do a diff on them to obtain an array of the differences (using CSVDiff) and need to delete the downloaded reports once I'm done. This is how I discovered the issue.