Skip to content

Commit b2707cb

Browse files
Besroyyawzhang
andauthored
Fix: set freed pointers to nullptr in destructors (eBay#849)
Set m_bytes and m_journal_entry to nullptr after manual deallocation to prevent potential double-free and use-after-free issues. This is a defensive programming practice that makes the code more robust against future changes and easier to debug. Co-authored-by: yawzhang <yawzhang@ebay.com>
1 parent b65c914 commit b2707cb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HomestoreConan(ConanFile):
1111
name = "homestore"
12-
version = "7.1.3"
12+
version = "7.1.4"
1313

1414
homepage = "https://github.com/eBay/Homestore"
1515
description = "HomeStore Storage Engine"

src/lib/index/index_service.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ IndexBuffer::IndexBuffer(BlkId blkid, uint32_t buf_size, uint32_t align_size) :
248248
IndexBuffer::IndexBuffer(uint8_t* raw_bytes, BlkId blkid) : m_blkid(blkid), m_bytes{raw_bytes} {}
249249

250250
IndexBuffer::~IndexBuffer() {
251-
if (m_bytes) { hs_utils::iobuf_free(m_bytes, sisl::buftag::btree_node); }
251+
if (m_bytes) {
252+
hs_utils::iobuf_free(m_bytes, sisl::buftag::btree_node);
253+
m_bytes = nullptr;
254+
}
252255
}
253256

254257
std::string IndexBuffer::to_string() const {

src/lib/replication/repl_dev/common.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ ReplServiceError repl_req_ctx::init(repl_key rkey, journal_type_t op_code, bool
5959
}
6060

6161
repl_req_ctx::~repl_req_ctx() {
62-
if (m_journal_entry) { m_journal_entry->~repl_journal_entry(); }
62+
if (m_journal_entry) {
63+
m_journal_entry->~repl_journal_entry();
64+
m_journal_entry = nullptr;
65+
}
6366
}
6467

6568
void repl_req_ctx::create_journal_entry(bool is_raft_buf, int32_t server_id) {

0 commit comments

Comments
 (0)