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

Unhandled Exception while disposing ExtFileStream #10

Open
christopher-fabian opened this issue Dec 12, 2022 · 7 comments
Open

Unhandled Exception while disposing ExtFileStream #10

christopher-fabian opened this issue Dec 12, 2022 · 7 comments

Comments

@christopher-fabian
Copy link

Hi,

I get an unhandled exception during disposing the ExtFileStream.
The target framework of my application is .NET 7.

I do simple copy operations of large files (up to 2 GB) from my NTFS-Disk to a Micro-SD (Ext4).

Source


  ExtDisk disk = ExtDisk.Open(diskNumber);
  ExtFileSystem fileSystem = ExtFileSystem.Open(disk, disk.Partitions[0]);

  byte[] buffer = File.ReadAllBytes(sourcePath);

  using ExtFileStream stream = fileSystem.OpenFile(destinationPath, FileMode.Create, FileAccess.Write);
  stream.Write(buffer, 0, buffer.Length);
  stream.Close();

The operation is successful but after the call of Dispose via the using-operator or calling Dispose I get the following exception:
grafik
grafik
grafik

Is this the default behavior?
Any idea for a workaround?

~Best Regards

@nickdu088
Copy link
Owner

Compile as release mode and try again.

@christopher-fabian
Copy link
Author

Same result in release mode:

grafik

@nickdu088
Copy link
Owner

Then it could be heap corruption.

@christopher-fabian
Copy link
Author

Do you have any idea how to check if the heap is corrupted and/or how to fix it? I‘m not familar with problems like this.

@nickdu088
Copy link
Owner

Just a quick glimpse the screen shot you attached, it seems you are using x64 release, as you can see ext4_write takes uint64 as input, however extfilestream passes int32.

You said you were copying large file (2gb). This may be the reason.

Try x86 mode, or use smaller file

@christopher-fabian
Copy link
Author

Thank you for your tips.

I found out the error only occurs when ExtFileStream.Close() is called shortly before disposing.

If I skip closing the stream before disposing, it works.
But on the other hand I get a memory leak, the RAM is not released properly.

Is disposing not closing the stream at all? I think this would be the expected behavior.

Maybe we can improve the whole thing, Dispose should better not throw an error exception if the stream is closed.

@nickdu088
Copy link
Owner

ExtFileStream inherits . Net Stream class and override close.
https://github.com/nickdu088/SharpExt4/blob/main/SharpExt4/ExtFileStream.h#L37

It should be all handled by Stream base class.

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

2 participants