From: malaterre Date: Mon, 7 Jun 2004 20:16:29 +0000 (+0000) Subject: ENH: scandir was leaking like crazy, we shouldnt be using this function anyway X-Git-Tag: Version0.5.bp~151 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=854ec81bfcffd6f0e5939789b0ffbc410f7910b7;p=gdcm.git ENH: scandir was leaking like crazy, we shouldnt be using this function anyway --- diff --git a/src/gdcmDirList.cxx b/src/gdcmDirList.cxx index 5f8f3ccc..e3a00ccc 100644 --- a/src/gdcmDirList.cxx +++ b/src/gdcmDirList.cxx @@ -92,9 +92,15 @@ void gdcmDirList::Explore(std::string dirName,bool recursive) } #else + // None of these functions is in POSIX. The functions scandir() and + // alphasort() are from BSD 4.3, and have been available under Linux since + // libc4. Libc4 and libc5 use the more precise prototype + struct dirent **namelist; int n=scandir(dirName.c_str(), &namelist, 0, alphasort); + //if n < 0 should raise error + for (int i= 0;i < n; i++) { fileName=namelist[i]->d_name; @@ -107,7 +113,9 @@ void gdcmDirList::Explore(std::string dirName,bool recursive) { this->push_back(dirName+fileName); } + free(namelist[i]); } + free(namelist); #endif }