From a5e88fcf11ebb16d4a1405b21cf6f895b37f185e Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 1 May 2015 14:21:35 -0400 Subject: [PATCH] librbd: invoking RBD::open twice will leak memory Signed-off-by: Jason Dillaman --- src/librbd/librbd.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); -- 2.47.3