]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
FileStore: fix fd and tmpfd leaks in _detect_fs()
authorSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 22:22:35 +0000 (15:22 -0700)
committerSamuel Just <sam.just@inktank.com>
Wed, 26 Sep 2012 17:16:24 +0000 (10:16 -0700)
CID 717088: Resource leak (RESOURCE_LEAK)At (11): Handle variable "tmpfd" going
out of scope leaks the handle.

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/os/FileStore.cc

index 6b13e7906fbf74e94c2000b8df733873e28b051b..2b6742b186b0c44eb22310bcb3173f083654763e 100644 (file)
@@ -1353,6 +1353,7 @@ int FileStore::_detect_fs()
       *_dout << "Got error " + cpp_strerror(ret) + ". ";
     *_dout << "If you are using ext3 or ext4, be sure to mount the underlying "
           << "file system with the 'user_xattr' option." << dendl;
+    TEMP_FAILURE_RETRY(::close(tmpfd));
     return -ENOTSUP;
   }
 
@@ -1385,13 +1386,17 @@ int FileStore::_detect_fs()
     return -errno;
 
   int r = _test_fiemap();
-  if (r < 0)
+  if (r < 0) {
+    TEMP_FAILURE_RETRY(::close(fd));
     return -r;
+  }
 
   struct statfs st;
   r = ::fstatfs(fd, &st);
-  if (r < 0)
+  if (r < 0) {
+    TEMP_FAILURE_RETRY(::close(fd));
     return -errno;
+  }
   blk_size = st.f_bsize;
 
 #if defined(__linux__)