From afb6e012a969395f45655e13b5b24c4633bb8e66 Mon Sep 17 00:00:00 2001 From: darode Date: Fri, 16 Jul 2010 12:28:49 +0000 Subject: [PATCH] 2010-07-16 Dario Rodriguez * misc/pandora_file.cc: fixed unclosed directory with function closedir and control posible delete errors. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3018 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/ChangeLog | 5 +++++ pandora_agents/win32/misc/pandora_file.cc | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index 26820bd65a..139600fee0 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,8 @@ +2010-07-16 Dario Rodriguez + + * misc/pandora_file.cc: fixed unclosed directory with function closedir + and control posible delete errors. + 2010-07-16 Dario Rodriguez * win32/bin/util/unzip.exe: Added to bin/utils to use it to unzip diff --git a/pandora_agents/win32/misc/pandora_file.cc b/pandora_agents/win32/misc/pandora_file.cc index b8f673da1f..9b8b110cff 100644 --- a/pandora_agents/win32/misc/pandora_file.cc +++ b/pandora_agents/win32/misc/pandora_file.cc @@ -164,10 +164,16 @@ Pandora_File::removeDir (const string filepath) { /*If its a file, delete it*/ if(errno == ENOTDIR) { if (remove (filepath.c_str ()) == -1) { + + /*Close dir oppened*/ + closedir(dir); return DELETE_ERROR; } return 0; } else { + + /*Close dir oppened*/ + closedir(dir); return DELETE_ERROR; } } @@ -187,13 +193,20 @@ Pandora_File::removeDir (const string filepath) { case S_IFDIR: /*If tmp is a folder, recursive delete*/ if ( (strcmp(dir_content->d_name,".") != 0) && (strcmp(dir_content->d_name,"..") != 0)){ - removeDir(tmp); + if( removeDir(tmp) == DELETE_ERROR ) { + + /*Close dir oppened*/ + closedir(dir); + return DELETE_ERROR; + } } break; default: /*If tmp is a file, it will be deleted*/ if (remove (tmp.c_str ()) == -1) { + /*Close dir oppened*/ + closedir(dir); return DELETE_ERROR; } break; @@ -205,6 +218,8 @@ Pandora_File::removeDir (const string filepath) { /*When the folder is empty, delete the folder*/ if (rmdir (filepath.c_str ()) == -1) { + /*Close dir oppened*/ + closedir(dir); return DELETE_ERROR; }