Menu

#89 Undisposed Stream Issue in pdfClown.Net

0.1.2.1
open
nobody
5
2017-08-14
2017-08-14
Devin R.
No

I believe there's an error in your library than can cause streams to be undisposed.

If you take advantage of the public File(string path) constructor it creates a bytes.Stream object and a FileStream object which are never disposed. This was creating an issue where when I opened a file via File("pathToFile") and then I later went to delete that file I was getting a file in use error.

I had this code

using(var pdf = new files.File("pathToFile"))
{

}

//delete file

and it failed with the error "The process cannot access the file 'pathToFile' because it is being used by another process."

I switched to the following code:

using(var fs = new FileStream("pathToFile", FileMode.Open))
using(var pfs = new bytes.Stream(fs))
using(var pdf = new files.File(pfs))
{

}

//delete file

and the operation completes successfully.

I believe the problem stems from this https://sourceforge.net/p/clown/code/HEAD/tree/trunk/dotNET/pdfclown.lib/src/org/pdfclown/files/File.cs#l94 where it's creating streams without references to dispose of them later. I have a pretty good idea on how to fix this but it'd required a decent restructuring of the code and I didn't know how open you were to that.

Discussion


Log in to post a comment.