From 24268cf4309267a0a1e32e28379cf7eafac00bca 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 (cherry picked from commit a5e88fcf11ebb16d4a1405b21cf6f895b37f185e) --- src/librbd/librbd.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); -- 2.47.3