Skip to content

Commit d5f7875

Browse files
committed
fix(test): fix double-free in HandleDetachAttach test
- Problem: calling h2.release() followed by shm::remove(id) causes use-after-free - h2.release() internally calls shm::release(id) which frees the id structure - shm::remove(id) then accesses the freed id pointer -> crash - Solution: detach the id from handle first, then call shm::remove(id) - h2.detach() returns the id without releasing it - shm::remove(id) can then safely clean up both memory and disk file - This completes the fix for all ShmTest double-free issues
1 parent 0ecf1a4 commit d5f7875

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

test/test_shm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,10 @@ TEST_F(ShmTest, HandleDetachAttach) {
406406
h2.attach(id);
407407
EXPECT_TRUE(h2.valid());
408408

409-
// Clean up
410-
h2.release();
411-
shm::remove(id);
409+
// Clean up - use h2.clear() or shm::remove(id) alone, not both
410+
// Option 1: Use handle's clear() which calls shm::remove(id) internally
411+
id = h2.detach(); // Detach first to get the id without releasing
412+
shm::remove(id); // Then remove to clean up both memory and disk file
412413
}
413414

414415
// Test writing and reading data through shared memory

0 commit comments

Comments
 (0)