From ba28fa3f149c949870258465a8031a9e83839781 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Tue, 3 Dec 2024 14:02:52 +0100 Subject: [PATCH] [#532] Add resizable shared memory tests for segment leak fix --- .../src/resizable_shared_memory/dynamic.rs | 1 - .../tests/resizable_shared_memory_tests.rs | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/iceoryx2-cal/src/resizable_shared_memory/dynamic.rs b/iceoryx2-cal/src/resizable_shared_memory/dynamic.rs index 37dfe1108..2ac046933 100644 --- a/iceoryx2-cal/src/resizable_shared_memory/dynamic.rs +++ b/iceoryx2-cal/src/resizable_shared_memory/dynamic.rs @@ -680,7 +680,6 @@ where match state.shared_memory_map.get(segment_id) { Some(entry) => { deallocation_call(entry); - //entry.shm.deallocate_bucket(offset); if entry.unregister_offset() == ShmEntryState::Empty && segment_id != state.current_idx { diff --git a/iceoryx2-cal/tests/resizable_shared_memory_tests.rs b/iceoryx2-cal/tests/resizable_shared_memory_tests.rs index 0a1c3ce37..d804ec9aa 100644 --- a/iceoryx2-cal/tests/resizable_shared_memory_tests.rs +++ b/iceoryx2-cal/tests/resizable_shared_memory_tests.rs @@ -946,6 +946,44 @@ mod resizable_shared_memory { assert_that!(sut_viewer.number_of_active_segments(), eq 1); } + #[test] + fn register_segment_that_was_resized_on_the_first_allocation_leads_to_a_unmap_of_the_old_segment_on_viewer_side< + Shm: SharedMemory, + Sut: ResizableSharedMemory, + >() { + let config = generate_isolated_config::(); + let storage_name = generate_name(); + + let sut = Sut::MemoryBuilder::new(&storage_name) + .config(&config) + .max_chunk_layout_hint(Layout::new::()) + .max_number_of_chunks_hint(1) + .allocation_strategy(AllocationStrategy::BestFit) + .create() + .unwrap(); + + let sut_viewer = Sut::ViewBuilder::new(&storage_name) + .config(&config) + .open() + .unwrap(); + + let chunk_small = sut.allocate(Layout::new::()).unwrap().offset; + unsafe { + sut_viewer + .register_and_translate_offset(chunk_small) + .unwrap() + }; + unsafe { sut_viewer.unregister_offset(chunk_small) }; + + let chunk = sut.allocate(Layout::new::()).unwrap().offset; + + // this shall release the old `u8` segment and map the new `u64` segment, therefore + // leading to 1 active segment + unsafe { sut_viewer.register_and_translate_offset(chunk).unwrap() }; + + assert_that!(sut_viewer.number_of_active_segments(), eq 1); + } + #[instantiate_tests(, resizable_shared_memory::dynamic::DynamicMemory>>)] mod posix {}