Memory leak in zlib with void[]

Ald Sannes aldarri_s at yahoo.com
Fri Nov 9 08:36:02 PST 2007


torhu Wrote:

> Ald Sannes wrote:
> > Hello.
> > I have the following code:
> > 
> > 		int zipFileSize = getSize(fileName);
> > 		
> > 		void[] zipFileContent = uncompress(read(fileName), 0, 24);
> > 		
> > 		delete zipFileContent;
> > 				
> > 		return cast (char []) zipFileContent;
> > 
> > I am unzipping some 50 Mbytes of data, and some 50 Mbytes are not being freed.
> > 
> > The delete statement was added to check for memory leaks, and it is there to check is memory leak.
> > 
> > The program does nothing else (commented out).
> > 
> > Where to free the memory?
> 
> You can't free zipFileContent, and then use it afterwards.  Free it when 
> you don't need it anymore.  You might also want to look at std.zip, 
> which is higher level than std.zlib.

And who exactly is going to stop me?
Seriously, I know that it is nullified during the deletion operation, but the complaint is that memory still leaks.

Am also extremely unhappy to report that using 

char[][] wordList = std.regexp.split(line, " \\$|\"|1|2|3|4|5|6|7|8|9|0|-|_|\\s|[.]|,|!|@|#|%|^|`|~|:|;|\"|'|<|>|[.]|,|/|\\|\\*", "g");

may leak up to a Gb of memory.  That is 2^30 bytes.

I remember a discussion a while ago about the GC not freeing arrays after concatenation, and that it was fix.  Perhaps that has something to do with it?


More information about the Digitalmars-d-learn mailing list