Skip to content

Commit 5eef791

Browse files
committed
Fix errors found by AddressSanitizer
1 parent 354e266 commit 5eef791

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

src/pool/pool_scalable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static void tbb_pool_finalize(void *pool) {
167167
pthread_once(&tbb_is_initialized, load_tbb_symbols);
168168
struct tbb_memory_pool *pool_data = (struct tbb_memory_pool *)pool;
169169
g_tbb_ops.pool_destroy(pool_data->tbb_pool);
170+
free(pool);
170171
}
171172

172173
static void *tbb_malloc(void *pool, size_t size) {

test/common/provider.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "base.hpp"
1919
#include "cpp_helpers.hpp"
20+
#include "test_helpers.h"
2021

2122
namespace umf_test {
2223

@@ -68,10 +69,16 @@ struct provider_malloc : public provider_base_t {
6869
align = 8;
6970
}
7071

72+
// aligned_malloc returns a valid pointer despite not meeting the
73+
// requirement of 'size' being multiple of 'align' even though the
74+
// documentation says that it has to. AddressSanitizer returns an
75+
// error because of this issue.
76+
size_t aligned_size = ALIGN_UP(size, align);
77+
7178
#ifdef _WIN32
72-
*ptr = _aligned_malloc(size, align);
79+
*ptr = _aligned_malloc(aligned_size, align);
7380
#else
74-
*ptr = ::aligned_alloc(align, size);
81+
*ptr = ::aligned_alloc(align, aligned_size);
7582
#endif
7683

7784
return (*ptr) ? UMF_RESULT_SUCCESS

test/common/test_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ static inline void UT_OUT(const char *format, ...) {
6969
(unsigned long long)(rhs)), \
7070
0)))
7171

72+
#define ALIGN_UP(size, align) (((size) + (align)-1) & ~((align)-1))
73+
7274
int bufferIsFilledWithChar(void *ptr, size_t size, char c);
7375

7476
int buffersHaveSameContent(void *first, void *second, size_t size);

test/memoryPoolAPI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ TEST_F(test, memoryPoolWithCustomProvider) {
105105
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
106106
ASSERT_NE(hPool, nullptr);
107107

108+
umfPoolDestroy(hPool);
109+
108110
umfMemoryProviderDestroy(hProvider);
109111
}
110112

test/pools/disjoint_pool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ TEST_F(test, freeErrorPropagation) {
5757
static constexpr size_t size = 1024;
5858
void *ptr = umfPoolMalloc(pool, size);
5959

60+
// Check for simulated free error propagation
6061
freeReturn = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
6162
auto freeRet = umfPoolFree(pool, ptr);
6263

6364
EXPECT_EQ(freeRet, freeReturn);
65+
66+
// Actually free the allocated memory
67+
freeReturn = UMF_RESULT_SUCCESS;
68+
freeRet = umfPoolFree(pool, ptr);
69+
70+
EXPECT_EQ(freeRet, freeReturn);
6471
}
6572

6673
TEST_F(test, sharedLimits) {

0 commit comments

Comments
 (0)