File tree Expand file tree Collapse file tree 3 files changed +21
-13
lines changed
Expand file tree Collapse file tree 3 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 4848endif ()
4949
5050add_library (swiftnet STATIC ${SOURCE_FILES} )
51- target_compile_options (swiftnet PRIVATE -O3 )
52- target_link_options (swiftnet PRIVATE -O3 )
51+ target_compile_options (swiftnet PRIVATE -O0 )
52+ target_link_options (swiftnet PRIVATE -O0 )
5353
5454if (DEFINED ENV{VCPKG_ROOT} AND DEFINED CMAKE_VCPKG_TARGET_TRIPLET)
5555 set (VCPKG_INCLUDE_DIR "$ENV{VCPKG_ROOT} /installed/${CMAKE_VCPKG_TARGET_TRIPLET} /include" )
Original file line number Diff line number Diff line change @@ -286,18 +286,24 @@ void allocator_destroy(struct SwiftNetMemoryAllocator* const memory_allocator) {
286286 break ;
287287 }
288288
289- free (current_stack );
290-
291289 #ifdef SWIFT_NET_DEBUG
292290 lock_ptr_status (current_stack );
293291
294- for (uint32_t i = 0 ; i < sizeof (uint8_t ) * (memory_allocator -> chunk_item_amount / 8 ) + 1 ; i ++ ) {
295- if (current_stack -> ptr_status + i != 0x00 ) {
296- for (uint8_t bit = 0 ; bit < 8 ; bit ++ ) {
297- if ((* (current_stack -> ptr_status + i ) & (1 << bit )) == 0x00 ) {
298- bytes_leaked += memory_allocator -> item_size ;
299- items_leaked ++ ;
300- }
292+ const uint32_t total_items = memory_allocator -> chunk_item_amount ;
293+ const uint32_t bytes = (total_items / 8 ) + 1 ;
294+
295+ for (uint32_t byte = 0 ; byte < bytes ; byte ++ ) {
296+ uint8_t mask = current_stack -> ptr_status [byte ];
297+
298+ for (uint8_t bit = 0 ; bit < 8 ; bit ++ ) {
299+ uint32_t idx = byte * 8 + bit ;
300+ if (idx >= total_items ) break ;
301+
302+ bool allocated = (mask & (1u << bit )) != 0 ;
303+
304+ if (allocated ) {
305+ items_leaked ++ ;
306+ bytes_leaked += memory_allocator -> item_size ;
301307 }
302308 }
303309 }
@@ -307,6 +313,8 @@ void allocator_destroy(struct SwiftNetMemoryAllocator* const memory_allocator) {
307313 free (current_stack -> ptr_status );
308314 #endif
309315
316+ free (current_stack );
317+
310318 current_stack = next_stack ;
311319 }
312320}
Original file line number Diff line number Diff line change @@ -21,13 +21,13 @@ endif()
2121
2222link_directories (${CMAKE_SOURCE_DIR} /../build /output )
2323
24- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 " )
24+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 " )
2525
2626file (GLOB SRC_FILES "${CMAKE_SOURCE_DIR} /src/*.c" )
2727
2828add_executable (run_tests ${SRC_FILES} )
2929
3030target_link_libraries (run_tests PRIVATE swiftnet -lpcap)
31- target_link_options (run_tests PRIVATE -g -O3 )
31+ target_link_options (run_tests PRIVATE -g -O0 )
3232
3333set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
You can’t perform that action at this time.
0 commit comments