]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
FileStore: fix leaked fd and check lseek in _test_fiemap
authorSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 22:18:13 +0000 (15:18 -0700)
committerSamuel Just <sam.just@inktank.com>
Wed, 26 Sep 2012 17:16:24 +0000 (10:16 -0700)
CID 716861: Other violation (CHECKED_RETURN)At (3): Calling function "lseek(fd,
off, 0)" without checking return value. This library function may fail and
return an error code.

CID 717090: Resource leak (RESOURCE_LEAK)At (10): Handle variable "fd" going
out of scope leaks the handle.

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

index 0ff995dfb05c73a1a3927311c4aded7d16ea5311..6b13e7906fbf74e94c2000b8df733873e28b051b 100644 (file)
@@ -1287,10 +1287,17 @@ int FileStore::_test_fiemap()
     // write a large extent
     char buf[len];
     memset(buf, 1, sizeof(buf));
-    ::lseek(fd, off, SEEK_SET);
-    int r = safe_write(fd, buf, sizeof(buf));
+    int r = ::lseek(fd, off, SEEK_SET);
+    if (r < 0) {
+      r = -errno;
+      derr << "_test_fiemap failed to lseek " << fn << ": " << cpp_strerror(r) << dendl;
+      TEMP_FAILURE_RETRY(::close(fd));
+      return r;
+    }
+    r = safe_write(fd, buf, sizeof(buf));
     if (r < 0) {
       derr << "_test_fiemap failed to write to " << fn << ": " << cpp_strerror(r) << dendl;
+      TEMP_FAILURE_RETRY(::close(fd));
       return r;
     }
   }