Fix closing database directory descriptor 43/38743/1
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 27 Apr 2015 18:37:44 +0000 (20:37 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 27 Apr 2015 18:37:44 +0000 (20:37 +0200)
Directory stream received from opendir() function wasn't closed
with proper closedir() function.
This patch fixes this bug.

Change-Id: Ie2a3efb55546251c12a1112861db767595bc374f

src/storage/Integrity.cpp

index 0b8e583..1735b9e 100644 (file)
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <fstream>
 #include <functional>
+#include <memory>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -108,6 +109,15 @@ void Integrity::deleteNonIndexedFiles(BucketPresenceTester tester) {
         return;
     }
 
+    std::unique_ptr<DIR, std::function<void(DIR*)>> dirStream(dirPtr,
+            [](DIR *dir) {
+                if (closedir(dir) < 0) {
+                    int err = errno;
+                    (void) err;
+                    LOGE("'closedir' function error [%d] : <%s>", err, strerror(err));
+                }
+            });
+
     while (errno = 0, (direntPtr = readdir(dirPtr)) != nullptr) {
         std::string filename = direntPtr->d_name;
         //ignore all special files (working dir, parent dir, index, checksums)