40 lines
1.3 KiB
Diff
40 lines
1.3 KiB
Diff
From f7e4a8faa920a1d9746b056e9820da13b5b488e7 Mon Sep 17 00:00:00 2001
|
|
From: Ming-Hung Tsai <mtsai@redhat.com>
|
|
Date: Wed, 28 Apr 2021 10:34:16 +0800
|
|
Subject: [PATCH] [all] Fix resource leaks
|
|
|
|
---
|
|
base/file_utils.cc | 4 +++-
|
|
thin-provisioning/cache_stream.cc | 2 +-
|
|
2 files changed, 4 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/base/file_utils.cc b/base/file_utils.cc
|
|
index e4f37228..82536608 100644
|
|
--- a/base/file_utils.cc
|
|
+++ b/base/file_utils.cc
|
|
@@ -155,8 +155,10 @@ file_utils::zero_superblock(std::string const &path)
|
|
throw runtime_error("out of memory");
|
|
|
|
memset(buffer, 0, SUPERBLOCK_SIZE);
|
|
- if (::write(fd.fd_, buffer, SUPERBLOCK_SIZE) != SUPERBLOCK_SIZE)
|
|
+ if (::write(fd.fd_, buffer, SUPERBLOCK_SIZE) != SUPERBLOCK_SIZE) {
|
|
+ free(buffer);
|
|
throw runtime_error("couldn't zero superblock");
|
|
+ }
|
|
}
|
|
|
|
//----------------------------------------------------------------
|
|
diff --git a/thin-provisioning/cache_stream.cc b/thin-provisioning/cache_stream.cc
|
|
index 002b6ba9..73b01b4e 100644
|
|
--- a/thin-provisioning/cache_stream.cc
|
|
+++ b/thin-provisioning/cache_stream.cc
|
|
@@ -62,7 +62,7 @@ chunk const &
|
|
cache_stream::get()
|
|
{
|
|
chunk_wrapper *w = new chunk_wrapper(*this);
|
|
- return w->c_;
|
|
+ return w->c_; // wrapper will get freed by the put method
|
|
}
|
|
|
|
void
|