mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
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
This commit is contained in:
parent
0ecf1a4137
commit
d5f787596a
@ -406,9 +406,10 @@ TEST_F(ShmTest, HandleDetachAttach) {
|
|||||||
h2.attach(id);
|
h2.attach(id);
|
||||||
EXPECT_TRUE(h2.valid());
|
EXPECT_TRUE(h2.valid());
|
||||||
|
|
||||||
// Clean up
|
// Clean up - use h2.clear() or shm::remove(id) alone, not both
|
||||||
h2.release();
|
// Option 1: Use handle's clear() which calls shm::remove(id) internally
|
||||||
shm::remove(id);
|
id = h2.detach(); // Detach first to get the id without releasing
|
||||||
|
shm::remove(id); // Then remove to clean up both memory and disk file
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test writing and reading data through shared memory
|
// Test writing and reading data through shared memory
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user