]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
FileJournal: fix memory leak in _open_file
authorSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 21:16:52 +0000 (14:16 -0700)
committerSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 21:59:25 +0000 (14:59 -0700)
CID 717087: Resource leak (RESOURCE_LEAK)At (16): Variable "buf" going out of
scope leaks the storage it points to.

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

index baee133340f43c17a14d241d26a7b5762e3e8108..8a15e9517ba5a147e8ca656deac95f66d986eee7 100644 (file)
@@ -323,13 +323,17 @@ int FileJournal::_open_file(int64_t oldsize, blksize_t blksize,
     uint64_t i = 0;
     for (; (i + write_size) <= (unsigned)max_size; i += write_size) {
       ret = ::pwrite(fd, static_cast<void*>(buf), write_size, i);
-      if (ret < 0)
+      if (ret < 0) {
+       delete [] buf;
        return -errno;
+      }
     }
     if (i < (unsigned)max_size) {
       ret = ::pwrite(fd, static_cast<void*>(buf), max_size - i, i);
-      if (ret < 0)
+      if (ret < 0) {
+       delete [] buf;
        return -errno;
+      }
     }
     delete [] buf;
   }