]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: invoking RBD::open twice will leak memory 4529/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 1 May 2015 18:21:35 +0000 (14:21 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 1 May 2015 18:21:35 +0000 (14:21 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/librbd.cc

index ea6e2a6c0eaa36485398a973e939bd145cf8de3b..4bdaf4311d781c5bc2abfe38e4eb1f62128afbf6 100644 (file)
@@ -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<ImageCtx*>(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<ImageCtx*>(image.ctx));
+      image.ctx = NULL;
+    }
+
     int r = librbd::open_image(ictx);
     if (r < 0) {
       tracepoint(librbd, open_image_exit, r);