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:
木头云 2025-11-30 05:38:59 +00:00
parent 0ecf1a4137
commit d5f787596a

View File

@ -406,9 +406,10 @@ TEST_F(ShmTest, HandleDetachAttach) {
h2.attach(id);
EXPECT_TRUE(h2.valid());
// Clean up
h2.release();
shm::remove(id);
// Clean up - use h2.clear() or shm::remove(id) alone, not both
// Option 1: Use handle's clear() which calls shm::remove(id) internally
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