Proposed fix for ~ofxDirList()

I would like to propose the following fix for what I think is a memory leak, due to forgetting to delete the individual elements of the previously allocated arrays (see constructor).

I might be wrong, but it looks like the ofxDirList destructor should delete like this:

	for(int k = 0; k < OF_DL_MAX_EXTS; k++)  
		delete[] allowedFileExt[k];  
	for(int k = 0; k < OF_DL_MAX_RESULTS; k++){  
		delete[] nameArray[k];  
		delete[] pathArray[k];  
	delete[] pathArray;  
	delete[] nameArray;  
	delete[] allowedFileExt;  

When I run it through the Mac MallocDebug performance tool, a previous leak dissapears. Can anyone confirm this?

P.S. I was wondering if limiting the file array to 200 items is a good idea. What happens if there’s a huge amount of items in a folder? Wouldn’t this be a good place to use a list or vector instead of char*[] and just allow it to grow as big as it needs?

Hey - good catch.
Also it would be a good idea to switch over to vector and strings. We made ofDirList before we had made the decision to switch OF over to C++ strings.

So I agree vector would be the way to go - then no worrying about allocation and freeing.

You’re welcome to take a stab at it :smiley:
Otherwise we’ll put it on our to do list!


[quote author=“theo”]You’re welcome to take a stab at it :smiley:
Otherwise we’ll put it on our to do list![/quote]

Sure. I’ve been wondering how to contibute more to the low-level development of the libraries anyway. As far as I could understand there’s an SVN out there, at least between you and Zach, right?

Cool - I’ll send you an email tomorrow, with more info regarding svn.

For now we might just want to put in the destructor fix as there is a good chance that ofDirList will soon use Poco’s file and directory reading functionality that is miles ahead of what ofDirList is currently doing.

If you want to check out poco - there is an xcode project here that includes the whole library in the testApp.

Poco library for os x here:

Anyway maybe it is interesting to check out?