]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: fix crypto related memory leaks
authorOr Ozeri <oro@il.ibm.com>
Sat, 9 Jan 2021 20:26:59 +0000 (22:26 +0200)
committerOr Ozeri <oro@il.ibm.com>
Sat, 9 Jan 2021 23:05:07 +0000 (01:05 +0200)
This commit fixes memory leaks introduced by the new librbd encryption feature

Signed-off-by: Or Ozeri <oro@il.ibm.com>
src/librbd/crypto/BlockCrypto.cc
src/librbd/crypto/BlockCrypto.h
src/librbd/crypto/CryptoObjectDispatch.cc

index c782807bd2a75f986d0bf8dd572b2af881556eb6..172bf146001f820d67b3e7e6092c62eaea31ebe0 100644 (file)
@@ -19,6 +19,14 @@ BlockCrypto<T>::BlockCrypto(CephContext* cct, DataCryptor<T>* data_cryptor,
   ceph_assert((block_size % data_cryptor->get_block_size()) == 0);
 }
 
+template <typename T>
+BlockCrypto<T>::~BlockCrypto() {
+  if (m_data_cryptor != nullptr) {
+    delete m_data_cryptor;
+    m_data_cryptor = nullptr;
+  }
+}
+
 template <typename T>
 int BlockCrypto<T>::crypt(ceph::bufferlist* data, uint64_t image_offset,
                            CipherMode mode) {
index a9f0ad3c0029854cf75e52e38b7242e6e2d7f14a..31b39a2b3a16265e4d5b301c922ebe1245c153e1 100644 (file)
@@ -21,6 +21,7 @@ public:
     }
     BlockCrypto(CephContext* cct, DataCryptor<T>* data_cryptor,
                 uint64_t block_size, uint64_t data_offset);
+    ~BlockCrypto();
 
     int encrypt(ceph::bufferlist* data, uint64_t image_offset) override;
     int decrypt(ceph::bufferlist* data, uint64_t image_offset) override;
index 5f6df63d88a0c6b6c314457519eaf726fd8bc675..c2c24c8ce2f36efa9fd1c034aa3797547c15a38a 100644 (file)
@@ -352,6 +352,7 @@ struct C_UnalignedObjectWriteRequest : public Context {
         if (io::util::trigger_copyup(image_ctx, object_no, io_context, ctx)) {
           return;
         }
+        delete ctx;
         object_exists = false;
       } else if (r < 0) {
         complete(r);