From 5bf6d2258336cccc6034d367e23008863cd7d9a0 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Tue, 25 Sep 2012 14:16:52 -0700 Subject: [PATCH] FileJournal: fix memory leak in _open_file 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 --- src/os/FileJournal.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index baee133340f43..8a15e9517ba5a 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -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(buf), write_size, i); - if (ret < 0) + if (ret < 0) { + delete [] buf; return -errno; + } } if (i < (unsigned)max_size) { ret = ::pwrite(fd, static_cast(buf), max_size - i, i); - if (ret < 0) + if (ret < 0) { + delete [] buf; return -errno; + } } delete [] buf; } -- 2.39.5