[Lldb-commits] [lldb] r124649 - /lldb/trunk/source/Commands/CommandCompletions.cpp

Greg Clayton gclayton at apple.com
Mon Jan 31 21:15:22 PST 2011


Author: gclayton
Date: Mon Jan 31 23:15:22 2011
New Revision: 124649

URL: http://llvm.org/viewvc/llvm-project?rev=124649&view=rev
Log:
Added a cleanup helper object to make sure the directory that was opened with "DIR *opendir(const char *)" is closed if it is valid with a call to "int closedir (DIR *)".

Modified:
    lldb/trunk/source/Commands/CommandCompletions.cpp

Modified: lldb/trunk/source/Commands/CommandCompletions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandCompletions.cpp?rev=124649&r1=124648&r2=124649&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandCompletions.cpp (original)
+++ lldb/trunk/source/Commands/CommandCompletions.cpp Mon Jan 31 23:15:22 2011
@@ -19,13 +19,13 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Core/FileSpec.h"
+#include "lldb/Core/FileSpecList.h"
 #include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/CommandCompletions.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
-#include "lldb/Core/FileSpecList.h"
 #include "lldb/Target/Target.h"
-#include "lldb/Interpreter/CommandCompletions.h"
-#include "lldb/Core/FileSpec.h"
-
+#include "lldb/Utility/CleanUp.h"
 
 using namespace lldb_private;
 
@@ -246,18 +246,16 @@
     }
     
     // Okay, containing_part is now the directory we want to open and look for files:
-    
-    DIR *dir_stream;
-    
-    dir_stream = opendir(containing_part);
-    if (dir_stream == NULL)
+
+    lldb_utility::CleanUp <DIR *, int> dir_stream (opendir(containing_part), NULL, closedir);
+    if (!dir_stream.is_valid())
         return matches.GetSize();
-        
+    
     struct dirent *dirent_buf;
     
     size_t baselen = end_ptr - partial_name_copy;
     
-    while ((dirent_buf = readdir(dir_stream)) != NULL) 
+    while ((dirent_buf = readdir(dir_stream.get())) != NULL) 
     {
         char *name = dirent_buf->d_name;
         





More information about the lldb-commits mailing list