mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
fix: [pmr] missed exception handling
This commit is contained in:
parent
ba66b59575
commit
efe1fe61dd
@ -47,8 +47,8 @@ void *new_delete_resource::do_allocate(std::size_t bytes, std::size_t alignment)
|
|||||||
return std::malloc(bytes);
|
return std::malloc(bytes);
|
||||||
}
|
}
|
||||||
#if defined(LIBIMP_CPP_17)
|
#if defined(LIBIMP_CPP_17)
|
||||||
LIBIMP_TRY {
|
|
||||||
/// @see https://en.cppreference.com/w/cpp/memory/c/aligned_alloc
|
/// @see https://en.cppreference.com/w/cpp/memory/c/aligned_alloc
|
||||||
|
LIBIMP_TRY {
|
||||||
return std::aligned_alloc(alignment, bytes);
|
return std::aligned_alloc(alignment, bytes);
|
||||||
} LIBIMP_CATCH(std::exception const &e) {
|
} LIBIMP_CATCH(std::exception const &e) {
|
||||||
log.error("std::aligned_alloc(alignment = {}, bytes = {}) fails. error = {}",
|
log.error("std::aligned_alloc(alignment = {}, bytes = {}) fails. error = {}",
|
||||||
@ -91,12 +91,8 @@ void new_delete_resource::do_deallocate(void* p, std::size_t bytes, std::size_t
|
|||||||
if (!verify_args(log, bytes, alignment)) {
|
if (!verify_args(log, bytes, alignment)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (alignment <= alignof(std::max_align_t)) {
|
auto std_free = [&log, bytes, alignment](void* p) noexcept {
|
||||||
/// @see https://en.cppreference.com/w/cpp/memory/c/free
|
/// @see https://en.cppreference.com/w/cpp/memory/c/free
|
||||||
std::free(p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#if defined(LIBIMP_CPP_17)
|
|
||||||
LIBIMP_TRY {
|
LIBIMP_TRY {
|
||||||
std::free(p);
|
std::free(p);
|
||||||
} LIBIMP_CATCH(std::exception const &e) {
|
} LIBIMP_CATCH(std::exception const &e) {
|
||||||
@ -106,12 +102,21 @@ void new_delete_resource::do_deallocate(void* p, std::size_t bytes, std::size_t
|
|||||||
log.error("std::free(p = {}) fails, alignment = {}, bytes = {}. error = unknown exception",
|
log.error("std::free(p = {}) fails, alignment = {}, bytes = {}. error = unknown exception",
|
||||||
p, alignment, bytes);
|
p, alignment, bytes);
|
||||||
}
|
}
|
||||||
#elif defined(LIBIMP_OS_WIN)
|
};
|
||||||
|
#if defined(LIBIMP_CPP_17)
|
||||||
|
std_free(p);
|
||||||
|
#else
|
||||||
|
if (alignment <= alignof(std::max_align_t)) {
|
||||||
|
std_free(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#if defined(LIBIMP_OS_WIN)
|
||||||
/// @see https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-free
|
/// @see https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-free
|
||||||
::_aligned_free(p);
|
::_aligned_free(p);
|
||||||
#else // try posix
|
#else // try posix
|
||||||
::free(p);
|
::free(p);
|
||||||
#endif
|
#endif
|
||||||
|
#endif // defined(LIBIMP_CPP_17)
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBPMR_NAMESPACE_END_
|
LIBPMR_NAMESPACE_END_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user