Skip to content

Commit

Permalink
Merge pull request #14834 from runsisi/wip-fix-double-free
Browse files Browse the repository at this point in the history
librbd: minor fixes for image trash move

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed May 5, 2017
2 parents bcae20d + c5c5d2f commit 965cfb5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/librbd/internal.cc
Expand Up @@ -1350,10 +1350,21 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
ImageCtx *ictx = new ImageCtx(image_name, "", nullptr, io_ctx, false);
int r = ictx->state->open(true);
if (r < 0) {
ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl;
delete ictx;
ictx = nullptr;

if (r != -ENOENT) {
return r;
ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl;
return r;
}

// try to get image id from the directory
r = cls_client::dir_get_id(&io_ctx, RBD_DIRECTORY, image_name, &image_id);
if (r < 0) {
if (r != -ENOENT) {
ldout(cct, 2) << "error reading image id from dirctory: "
<< cpp_strerror(-r) << dendl;
}
return r;
}
} else {
if (ictx->old_format) {
Expand All @@ -1376,6 +1387,9 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
}

BOOST_SCOPE_EXIT_ALL(ictx, cct) {
if (ictx == nullptr)
return;

bool is_locked = ictx->exclusive_lock != nullptr &&
ictx->exclusive_lock->is_lock_owner();
if (is_locked) {
Expand Down

0 comments on commit 965cfb5

Please sign in to comment.