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: v9.0.1~28^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a5e88fcf11ebb16d4a1405b21cf6f895b37f185e;p=ceph.git librbd: invoking RBD::open twice will leak memory Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index ea6e2a6c0eaa..4bdaf4311d78 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -99,6 +99,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); @@ -116,6 +121,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);