]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: invoking RBD::open twice will leak memory 6097/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 1 May 2015 18:21:35 +0000 (14:21 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 7 Oct 2015 22:42:37 +0000 (18:42 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit a5e88fcf11ebb16d4a1405b21cf6f895b37f185e)

src/librbd/librbd.cc

index a99f7d4725c84e766344693315b72531e79e59aa..d954d72451fd26c92129d97972246a2874170e0f 100644 (file)
@@ -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);
@@ -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);