Skip to content

Commit

Permalink
test/librados: Silence Coverity memory leak warnings
Browse files Browse the repository at this point in the history
Use Sam's scope_guard solution to stop warnings about leaked resources.

Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
  • Loading branch information
badone committed Dec 21, 2016
1 parent 9c54707 commit 7599f0d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/test/librados/TestCase.cc
Expand Up @@ -4,6 +4,7 @@
#include <errno.h>
#include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include "include/scope_guard.h"

using namespace librados;

Expand Down Expand Up @@ -42,7 +43,10 @@ void RadosTestNS::cleanup_all_objects(rados_ioctx_t ioctx)
rados_ioctx_snap_set_read(ioctx, LIBRADOS_SNAP_HEAD);
rados_ioctx_set_namespace(ioctx, LIBRADOS_ALL_NSPACES);
rados_list_ctx_t list_ctx;

ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx));
auto sg = make_scope_guard([&] { rados_nobjects_list_close(list_ctx); });

int r;
const char *entry = NULL;
const char *key = NULL;
Expand All @@ -53,7 +57,6 @@ void RadosTestNS::cleanup_all_objects(rados_ioctx_t ioctx)
rados_ioctx_set_namespace(ioctx, nspace);
ASSERT_EQ(0, rados_remove(ioctx, entry));
}
rados_nobjects_list_close(list_ctx);
}

std::string RadosTestPPNS::pool_name;
Expand Down Expand Up @@ -284,7 +287,10 @@ void RadosTest::cleanup_namespace(rados_ioctx_t ioctx, std::string ns)
rados_ioctx_snap_set_read(ioctx, LIBRADOS_SNAP_HEAD);
rados_ioctx_set_namespace(ioctx, ns.c_str());
rados_list_ctx_t list_ctx;

ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx));
auto sg = make_scope_guard([&] { rados_nobjects_list_close(list_ctx); });

int r;
const char *entry = NULL;
const char *key = NULL;
Expand All @@ -293,7 +299,6 @@ void RadosTest::cleanup_namespace(rados_ioctx_t ioctx, std::string ns)
rados_ioctx_locator_set_key(ioctx, key);
ASSERT_EQ(0, rados_remove(ioctx, entry));
}
rados_nobjects_list_close(list_ctx);
}

std::string RadosTestPP::pool_name;
Expand Down Expand Up @@ -343,12 +348,14 @@ void RadosTestPP::cleanup_namespace(librados::IoCtx ioctx, std::string ns)
ioctx.locator_set_key(it->get_locator());
ObjectWriteOperation op;
op.remove();

librados::AioCompletion *completion = s_cluster.aio_create_completion();
auto sg = make_scope_guard([&] { completion->release(); });

ASSERT_EQ(0, ioctx.aio_operate(it->get_oid(), completion, &op,
librados::OPERATION_IGNORE_CACHE));
completion->wait_for_safe();
ASSERT_EQ(0, completion->get_return_value());
completion->release();
}
}

Expand Down

0 comments on commit 7599f0d

Please sign in to comment.