Skip to content

Commit

Permalink
librbd: invoking RBD::open twice will leak memory
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit a5e88fc)
  • Loading branch information
Jason Dillaman committed Oct 7, 2015
1 parent 93c523c commit 24268cf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/librbd/librbd.cc
Expand Up @@ -219,6 +219,11 @@ namespace librbd {
ImageCtx *ictx = new ImageCtx(name, "", snap_name, io_ctx, false);
tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);

if (image.ctx != NULL) {
close_image(reinterpret_cast<ImageCtx*>(image.ctx));
image.ctx = NULL;
}

int r = librbd::open_image(ictx);
if (r < 0) {
tracepoint(librbd, open_image_exit, r);
Expand All @@ -236,6 +241,11 @@ namespace librbd {
ImageCtx *ictx = new ImageCtx(name, "", snap_name, io_ctx, true);
tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);

if (image.ctx != NULL) {
close_image(reinterpret_cast<ImageCtx*>(image.ctx));
image.ctx = NULL;
}

int r = librbd::open_image(ictx);
if (r < 0) {
tracepoint(librbd, open_image_exit, r);
Expand Down

0 comments on commit 24268cf

Please sign in to comment.