Skip to content

Commit

Permalink
Merge pull request openucx#6017 from dmitrygx/topic/ucs/mpool_elem_le…
Browse files Browse the repository at this point in the history
…ak_check

UCS/MPOOL: Make elem defined for Valgrind
  • Loading branch information
yosefe authored Dec 14, 2020
2 parents 475ab4e + b81d710 commit c8fa053
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ucs/datastruct/mpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static void ucs_mpool_chunk_leak_check(ucs_mpool_t *mp, ucs_mpool_chunk_t *chunk

for (i = 0; i < chunk->num_elems; ++i) {
elem = ucs_mpool_chunk_elem(mp->data, chunk, i);
VALGRIND_MAKE_MEM_DEFINED(elem, sizeof *elem);
if (elem->mpool != NULL) {
ucs_warn("object %p was not returned to mpool %s", elem + 1,
ucs_mpool_name(mp));
Expand Down
41 changes: 41 additions & 0 deletions test/gtest/ucs/test_mpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ class test_mpool : public ucs::test {
return UCS_LOG_FUNC_RC_CONTINUE;
}

static ucs_log_func_rc_t
mpool_log_leak_handler(const char *file, unsigned line,
const char *function, ucs_log_level_t level,
const ucs_log_component_config_t *comp_conf,
const char *message, va_list ap)
{
if (level == UCS_LOG_LEVEL_WARN) {
std::string err_str = format_message(message, ap);

if (err_str.find("was not returned to mpool test") !=
std::string::npos) {
return UCS_LOG_FUNC_RC_STOP;
}
}

return UCS_LOG_FUNC_RC_CONTINUE;
}

static const size_t header_size = 30;
static const size_t data_size = 152;
static const size_t align = 128;
Expand Down Expand Up @@ -203,3 +221,26 @@ UCS_TEST_F(test_mpool, infinite) {

ucs_mpool_cleanup(&mp, 1);
}

UCS_TEST_F(test_mpool, leak_check) {
ucs_mpool_t mp;
ucs_status_t status;

ucs_mpool_ops_t ops = {
ucs_mpool_chunk_malloc,
ucs_mpool_chunk_free,
NULL,
NULL
};

status = ucs_mpool_init(&mp, 0, header_size + data_size, header_size, align,
6, 18, &ops, "test");
ASSERT_UCS_OK(status);

void *obj = ucs_mpool_get(&mp);
EXPECT_TRUE(obj != NULL);
// Do not release allocated object

scoped_log_handler log_handler(mpool_log_leak_handler);
ucs_mpool_cleanup(&mp, 1);
}

0 comments on commit c8fa053

Please sign in to comment.