From 6a218c4df8d85c3d2c16237d4e7eb6e04ec47212 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 14 Sep 2017 17:19:26 +0300 Subject: [PATCH] Fix accounting posix_memalign. --- src/track/heaptrack_inject.cpp | 4 +++- src/track/heaptrack_preload.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/track/heaptrack_inject.cpp b/src/track/heaptrack_inject.cpp index 80abf3f..6265da7 100644 --- a/src/track/heaptrack_inject.cpp +++ b/src/track/heaptrack_inject.cpp @@ -175,7 +175,9 @@ struct posix_memalign { auto ret = original(memptr, alignment, size); if (!ret) { - heaptrack_malloc(*memptr, size); + size_t aligned_size = ((size + alignment - 1) / alignment) * alignment; + + heaptrack_malloc(*memptr, aligned_size); } return ret; } diff --git a/src/track/heaptrack_preload.cpp b/src/track/heaptrack_preload.cpp index 22815ae..eaf712a 100644 --- a/src/track/heaptrack_preload.cpp +++ b/src/track/heaptrack_preload.cpp @@ -260,7 +260,9 @@ int posix_memalign(void** memptr, size_t alignment, size_t size) noexcept int ret = hooks::posix_memalign(memptr, alignment, size); if (!ret) { - heaptrack_malloc(*memptr, size); + size_t aligned_size = ((size + alignment - 1) / alignment) * alignment; + + heaptrack_malloc(*memptr, aligned_size); } return ret; -- 2.7.4