From: Jason Dillaman Date: Fri, 1 May 2015 18:21:35 +0000 (-0400) Subject: librbd: invoking RBD::open twice will leak memory X-Git-Tag: v0.94.6~101^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F6097%2Fhead;p=ceph.git librbd: invoking RBD::open twice will leak memory Signed-off-by: Jason Dillaman (cherry picked from commit a5e88fcf11ebb16d4a1405b21cf6f895b37f185e) --- diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index a99f7d4725c8..d954d72451fd 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -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(image.ctx)); + image.ctx = NULL; + } + int r = librbd::open_image(ictx); if (r < 0) { tracepoint(librbd, open_image_exit, r); @@ -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(image.ctx)); + image.ctx = NULL; + } + int r = librbd::open_image(ictx); if (r < 0) { tracepoint(librbd, open_image_exit, r);