From d5f787596a793ebc0991873a11d75b1f2fa55a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=A4=B4=E4=BA=91?= Date: Sun, 30 Nov 2025 05:38:59 +0000 Subject: [PATCH] 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 --- test/test_shm.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_shm.cpp b/test/test_shm.cpp index 51e6b33..e284dd6 100644 --- a/test/test_shm.cpp +++ b/test/test_shm.cpp @@ -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