Subject: [Boost-bugs] [Boost C++ Libraries] #9248: boost::interprocess - delete_subdirectories_recursive Win32 HANDLE leak
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-10-14 13:29:34
#9248: boost::interprocess - delete_subdirectories_recursive Win32 HANDLE leak
---------------------------+------------------------------
Reporter: tomas.kotal@⦠| Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.55.0
Severity: Problem | Keywords:
---------------------------+------------------------------
I believe there is a memory leak in function
delete_subdirectories_recursive in
boost\interprocess\detail\os_file_functions.hpp:
{{{
#!c++
252.inline bool delete_subdirectories_recursive
253. (const std::string &refcstrRootDirectory, const char
*dont_delete_this, unsigned int count)
254.{
255. bool bSubdirectory = false; // Flag, indicating
whether
256. // subdirectories
have been found
257. void * hFile; // Handle to
directory
258. std::string strFilePath; // Filepath
259. std::string strPattern; // Pattern
260. winapi::win32_find_data_t FileInformation; // File information
261.
262. //Find all files and directories
263. strPattern = refcstrRootDirectory + "\\*.*";
264. hFile = winapi::find_first_file(strPattern.c_str(),
&FileInformation);
265. if(hFile != winapi::invalid_handle_value){
266. do{
267. //If it's not "." or ".." or the pointed root_level
dont_delete_this erase it
268. if(FileInformation.cFileName[0] != '.' &&
269. !(dont_delete_this && count == 0 &&
std::strcmp(dont_delete_this, FileInformation.cFileName) == 0)){
270. strFilePath.erase();
271. strFilePath = refcstrRootDirectory + "\\" +
FileInformation.cFileName;
272.
273. //If it's a directory, go recursive
274. if(FileInformation.dwFileAttributes &
winapi::file_attribute_directory){
275. // Delete subdirectory
276. if(!delete_subdirectories_recursive(strFilePath,
dont_delete_this, count+1))
277. return false;
278. }
279. //If it's a file, just delete it
280. else{
281. // Set file attributes
282. //if(::SetFileAttributes(strFilePath.c_str(),
winapi::file_attribute_normal) == 0)
283. //return winapi::get_last_error();
284. // Delete file
285. winapi::unlink_file(strFilePath.c_str());
286. }
287. }
288. //Go to the next file
289. } while(winapi::find_next_file(hFile, &FileInformation) == 1);
290.
291. // Close handle
292. winapi::find_close(hFile);
...
}}}
On line 277, if subsequent call to delete_subdirectories_recursive returns
false, the calling function returns also false. But handle hFile (defined
on 264) is never closed. I think line winapi::find_close(hFile); before
return statement is missing here.
I noticed the bug in boost version 1.45.0 and it seems like it's still
there in 1.55.0.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9248> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC