diff --git a/osrf_testing_tools_cpp/include/osrf_testing_tools_cpp/memory_tools/memory_tools_service.hpp b/osrf_testing_tools_cpp/include/osrf_testing_tools_cpp/memory_tools/memory_tools_service.hpp index f28670b..3f47291 100644 --- a/osrf_testing_tools_cpp/include/osrf_testing_tools_cpp/memory_tools/memory_tools_service.hpp +++ b/osrf_testing_tools_cpp/include/osrf_testing_tools_cpp/memory_tools/memory_tools_service.hpp @@ -87,6 +87,11 @@ struct MemoryToolsService void unignore(); + // Return ignored or not. + OSRF_TESTING_TOOLS_CPP_MEMORY_TOOLS_PUBLIC + bool + get_ignored(); + /// Adds a backtrace to the log message. /** Repeated calls do nothing, and only prints if a log is also printed. */ OSRF_TESTING_TOOLS_CPP_MEMORY_TOOLS_PUBLIC diff --git a/osrf_testing_tools_cpp/src/memory_tools/memory_tools_service.cpp b/osrf_testing_tools_cpp/src/memory_tools/memory_tools_service.cpp index 5984a5c..360d91c 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/memory_tools_service.cpp +++ b/osrf_testing_tools_cpp/src/memory_tools/memory_tools_service.cpp @@ -87,6 +87,12 @@ MemoryToolsService::unignore() impl_->ignored = false; } +bool +MemoryToolsService::get_ignored() +{ + return impl_->ignored; +} + void MemoryToolsService::print_backtrace() { diff --git a/osrf_testing_tools_cpp/src/memory_tools/testing_helpers.cpp b/osrf_testing_tools_cpp/src/memory_tools/testing_helpers.cpp index 34e3ac7..221920d 100644 --- a/osrf_testing_tools_cpp/src/memory_tools/testing_helpers.cpp +++ b/osrf_testing_tools_cpp/src/memory_tools/testing_helpers.cpp @@ -32,8 +32,14 @@ on_unexpected_malloc(AnyMemoryToolsCallback callback) on_malloc( [callback](MemoryToolsService & service) { if (g_malloc_unexpected.load()) { - service.unignore(); + bool ignored = service.get_ignored(); + if (ignored) { + service.unignore(); + } dispatch_callback(&callback, service); + if (ignored) { + service.ignore(); + } } }); } @@ -62,8 +68,14 @@ on_unexpected_realloc(AnyMemoryToolsCallback callback) on_realloc( [callback](MemoryToolsService & service) { if (g_realloc_unexpected.load()) { - service.unignore(); + bool ignored = service.get_ignored(); + if (ignored) { + service.unignore(); + } dispatch_callback(&callback, service); + if (ignored) { + service.ignore(); + } } }); } @@ -92,8 +104,14 @@ on_unexpected_calloc(AnyMemoryToolsCallback callback) on_calloc( [callback](MemoryToolsService & service) { if (g_calloc_unexpected.load()) { - service.unignore(); + bool ignored = service.get_ignored(); + if (ignored) { + service.unignore(); + } dispatch_callback(&callback, service); + if (ignored) { + service.ignore(); + } } }); } @@ -122,8 +140,14 @@ on_unexpected_free(AnyMemoryToolsCallback callback) on_free( [callback](MemoryToolsService & service) { if (g_free_unexpected.load()) { - service.unignore(); + bool ignored = service.get_ignored(); + if (ignored) { + service.unignore(); + } dispatch_callback(&callback, service); + if (ignored) { + service.ignore(); + } } }); }