[Mono-bugs] [Bug 62369][Wis] New - memory leak garbage problem
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 3 Aug 2004 12:42:21 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by kaya@kayaweed.net.
http://bugzilla.ximian.com/show_bug.cgi?id=62369
--- shadow/62369 2004-08-03 12:42:21.000000000 -0400
+++ shadow/62369.tmp.10760 2004-08-03 12:42:21.000000000 -0400
@@ -0,0 +1,245 @@
+Bug#: 62369
+Product: Mono: Runtime
+Version: unspecified
+OS:
+OS Details: WinXP SP1 US AND Linux DEBIAN UNSTABLE
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: packaging
+AssignedTo: duncan@ximian.com
+ReportedBy: kaya@kayaweed.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: memory leak garbage problem
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+At a end of a process i seek into a file, read from it, and write it back
+to an another file, using a byte[] variable as buffer.
+My routine is working but i memory leak.
+
+I made a test program to check where the memory leak came from.
+
+Steps to reproduce the problem:
+1.
+2.
+3.
+
+Actual Results:
+
+
+Expected Results:
+the memory should go up and down.
+Actually this just goes up.
+
+How often does this happen?
+every time
+
+Additional Information:
+
+the main.cs
+ public static void Main(string[] args)
+ {
+ IsoClass iso = new IsoClass();
+ iso.extractiso();
+
+ }
+
+here is the source file "xiso.cs".
+
+namespace Xiso
+{
+using System;
+using System.IO;
+using System.Text;
+using System.Data;
+using System.Net;
+using System.Net.Sockets;
+using System.Collections;
+
+ class IsoClass
+ {
+
+ public struct dirent
+ {
+ public long ltable; //left entry
+ public long rtable; //right entry
+ public long sector; //sector of file
+ public long size; //size of file
+ public int attribs; //file attributes
+ public int fnamelen; //filename lenght
+ public string fname; //filename
+ public long pad; //padding (unused)
+ }
+
+ const string HEADERDATA = "MICROSOFT*XBOX*MEDIA";
+ const int HEADERSIZE = 20;
+ const int HEADEROFF = 0x10000;
+ const int BUFFERSIZE = 0x40000; //256k buffer
+
+ FileStream fs; //File Handling
+ StreamReader w; //Stream
+
+ public byte[] buffer = new byte[0];
+
+ public void extractiso()
+ {
+ Console.WriteLine("Hello World!");
+ Console.WriteLine("Start of archive");
+ fs = new FileStream(@"D:\xbox\Xbox WhiteOut.iso", FileMode.Open,
+ FileAccess.Read);
+ // Create a character reader.
+ w = new StreamReader(fs);
+
+ // Create and change to Game directory
+ Directory.CreateDirectory("WhiteOut");
+ Directory.SetCurrentDirectory("WhiteOut");
+
+ // Set the StreamReader file pointer to the end.
+ w.BaseStream.Seek( HEADEROFF, SeekOrigin.Begin);
+ byte[] bufheader = new byte[20];
+ int size = w.BaseStream.Read(bufheader, 0, bufheader.Length);
+ //Console.WriteLine("Size lu " + size);
+ if(size != 0)
+ {
+ string s=System.Text.Encoding.ASCII.GetString(bufheader,0,HEADERSIZE);
+ bufheader = null;
+ if (s.Equals("MICROSOFT*XBOX*MEDIA"))
+ {
+ Console.WriteLine("Is a xbox iso");
+ //Error file doesnt appear to be a xbox iso image
+ }
+ //Sector that root directory table resides in
+ byte[] buf = new byte[4];
+ size = w.BaseStream.Read(buf, 0, 4);
+ long sectorroot = ((buf[3]<<24)+(buf[2]<<16)+(buf[1]<<8)+(buf[0]<< 0 ));
+ Console.WriteLine("Sector root directory ["+ sectorroot + "]");
+ //Size of root directory table in bytes
+ buf = new byte[4];
+ size = w.BaseStream.Read(buf, 0, 4);
+ int sizeroot = ((buf[3]<<24)+(buf[2]<<16)+(buf[1]<<8)+(buf[0]<< 0 ));
+ Console.WriteLine("Size root directory ["+ sizeroot + "]");
+ //discard FILETIME structure representing image creation time
+ w.BaseStream.Seek( 8, SeekOrigin.Current);
+ //discard unused
+ w.BaseStream.Seek( 0x7c8, SeekOrigin.Current);
+ buf = new byte[20];
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ s = System.Text.Encoding.ASCII.GetString(buf,0,buf.Length);
+ if (s.Equals("MICROSOFT*XBOX*MEDIA"))
+ {
+ Console.WriteLine("Is a xbox iso 2");
+ //Error possible corruption?
+ }
+ //Done With HEADER
+ buf = null;
+ s = null;
+ handling(sectorroot*2048, (int)sectorroot);
+ }
+ Console.WriteLine("End of archive");
+ w.Close();
+ fs.Close();
+ w = null;
+ fs = null;
+ // End extractiso
+ }
+
+ private void handling(long offset, int dtable)
+ {
+ dirent cur = new dirent();
+
+ // Start from the beginning
+ w.BaseStream.Seek(offset, SeekOrigin.Begin);
+ Console.WriteLine("Next Offset [" + offset + "]");
+
+ //time to fill the structure
+ byte[] buf = new byte[2];
+ //ltable offset from current
+ int size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.ltable = ((buf[1]<<8) | (buf[0]));
+ Console.WriteLine("ltable offset ["+ cur.ltable + "]");
+
+ //rtable offset from current
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.rtable = ((buf[1]<<8) | (buf[0]));
+ Console.WriteLine("rtable offset ["+ cur.rtable + "]");
+
+ buf = new byte[4];
+ //sector of file
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.sector = ((buf[3]<<24) | (buf[2]<<16) | (buf[1]<<8) | buf[0]);
+ Console.WriteLine("Sector of file ["+ cur.sector + "]");
+ //file size
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.size = ((buf[3]<<24) | (buf[2]<<16) | (buf[1]<<8) | buf[0]);
+ Console.WriteLine("Size of file ["+ cur.size + "]");
+
+ buf = new byte[1];
+ //file attributes
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.attribs = ((buf[0]<<0));
+ Console.WriteLine("file attributes ["+ cur.attribs + "]");
+ //filename length
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.fnamelen = ((buf[0]<<0));
+ Console.WriteLine("length of filename ["+ cur.fnamelen + "]");
+
+ // Filename
+ buf = new byte[cur.fnamelen];
+ size = w.BaseStream.Read(buf, 0, buf.Length);
+ cur.fname = System.Text.Encoding.ASCII.GetString(buf, 0, cur.fnamelen);
+ Console.WriteLine("Filename ["+ cur.fname + "]\n");
+ buf = null;
+ if((cur.fname != null) && (cur.attribs == 16)) // attribs is a DIR
+ {
+ Console.WriteLine("Creating directory [" + cur.fname + "]");
+ Directory.CreateDirectory(cur.fname);
+ Directory.SetCurrentDirectory(cur.fname);
+ //Call back handling
+ handling(cur.sector*2048, (int)cur.sector);
+ Directory.SetCurrentDirectory(@"..");
+ }
+ else
+ {
+ //So now we have to extract
+ extract(cur);
+ }
+ if(cur.rtable != 0)
+ {
+ Console.WriteLine("rtable" + cur.sector + "==" + cur.rtable);
+ handling(dtable*2048+(cur.rtable*4), dtable);
+ }
+ if (cur.ltable != 0)
+ {
+ Console.WriteLine("ltable" + cur.sector + "==" + cur.ltable);
+ handling(dtable*2048+(cur.ltable*4), dtable);
+ }
+
+ //End handling
+ }
+
+ private void extract(dirent cur)
+ {
+ // Create a new stream to load this photo into
+ System.IO.FileStream stream = new System.IO.FileStream(cur.fname,
+ System.IO.FileMode.Create);
+
+ w.BaseStream.Seek(cur.sector*2048, SeekOrigin.Begin);
+ // Create a buffer to hold the stream bytes
+ byte[] buffer = new byte[cur.size];
+ w.BaseStream.Read(buffer, 0, buffer.Length);
+ // Read the bytes from this stream
+ stream.Write(buffer, 0, (int)buffer.Length);
+ // Now we can close the stream
+ stream.Close();
+ buffer = null;
+ return;
+ }
+ }
+}