It appears that the FAT chains are not getting fully cleaned up inside the FAT tables. The last sector in the chain is left as 0xFFFFFFFE instead of 0xFFFFFFFF. This results in fragmentation of the file and a steady increase in the files size.
I am looking into the cause however I figured I should let you know as you may know better candidate locations.
I found two candidate positions, fixing them reduced the garbage generated significantly, however some is still generated.
First error, CompoundFile.FreeChain
Convert to (remove the -1 in the loop).
Second error, CompoundFile.FreeMiniChain
Convert to (remove the -1 in the loop).
All changes pass all unit tests, garbage generated is reduced about 80%.
PS:
Turns out there is another part that's broken, you fixed this for the normal chain but not for the mini chain.
// Write End of Chain in MiniFAT ---------------------------------------
if (nth_sector_to_remove > 0 && sectorChain.Count > 0)
{
miniFATView.Seek(sectorChain[nth_sector_to_remove - 1].Id * 4, SeekOrigin.Begin);
miniFATView.Write(BitConverter.GetBytes(Sector.ENDOFCHAIN), 0, 4);
}
~~~~~~~~~~~~~~~~~~~~~
It appears there is another memory leak related to directory allocation. I am currently hunting it down.
Thank you very much. I committed all suggested changes.
I'm going to introduce some Unit Test more specific to these issues.