Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File handle not closed/disposed if exception is thrown #99

Open
swingnchad opened this issue Apr 21, 2023 · 0 comments
Open

File handle not closed/disposed if exception is thrown #99

swingnchad opened this issue Apr 21, 2023 · 0 comments

Comments

@swingnchad
Copy link

swingnchad commented Apr 21, 2023

If I pass an invalid or corrupt heic file to the HeifImage constructor, an exception is thrown without closing the file. If I try to delete the file I get an access violation exception.

            try
            {                
                using (var img = new HeifImage(heicImageFile)) // HeifException thrown here: "Heif image exception - Invalid input: No 'ftyp' box"
                using (var primary = img.PrimaryImage())
                {
                    primary.Write(jpegImageFile, 100);
                }

                File.Delete(heicImageFile);                
            }
            catch (Exception ex)
            {
                File.Delete(heicImageFile); // IOException thrown here: "The process cannot access the file xxx.heic because it is being used by another process."
            }

I would suggest you close/dispose the file handle in the finally block of a try/catch/finally so there are no memory leaks or file handles left open from an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant