]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: C_SaferCond memory leak
authorJason Dillaman <dillaman@redhat.com>
Thu, 26 Feb 2015 21:58:07 +0000 (16:58 -0500)
committerJason Dillaman <dillaman@redhat.com>
Fri, 27 Feb 2015 15:19:21 +0000 (10:19 -0500)
Unlike the other Context derived classes, C_SaferCond is not
a suicidal object which deletes itself.  Swap heap allocations
of C_SaferCond to stack-based allocations as a result.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/internal.cc

index 24ef4156cf71fcbafcb17adb7923a14820f18f4e..e2e90d2745a67f4d795b5a5a61e0bf1f8e6372de 100644 (file)
@@ -718,9 +718,9 @@ namespace librbd {
   }
 
   void ImageCtx::flush_async_operations() {
-    C_SaferCond *ctx = new C_SaferCond();
-    flush_async_operations(ctx);
-    ctx->wait();
+    C_SaferCond ctx;
+    flush_async_operations(&ctx);
+    ctx.wait();
   }
 
   void ImageCtx::flush_async_operations(Context *on_finish) {
index 7fa201230ee0c825d560d9a340c92dcb3c9daa27..cdf3f9bc5124ab51393258725372667aec65769e 100644 (file)
@@ -160,14 +160,14 @@ namespace librbd {
     assert(!ictx->image_watcher->is_lock_supported() ||
           ictx->image_watcher->is_lock_owner());
 
-    C_SaferCond *ctx = new C_SaferCond();
+    C_SaferCond ctx;
     ictx->snap_lock.get_read();
-    AsyncTrimRequest *req = new AsyncTrimRequest(*ictx, ctx, ictx->size,
+    AsyncTrimRequest *req = new AsyncTrimRequest(*ictx, &ctx, ictx->size,
                                                 newsize, prog_ctx);
     ictx->snap_lock.put_read();
     req->send();
 
-    int r = ctx->wait();
+    int r = ctx.wait();
     if (r < 0) {
       lderr(ictx->cct) << "warning: failed to remove some object(s): "
                       << cpp_strerror(r) << dendl;
@@ -1621,7 +1621,7 @@ reprotect_and_return_err:
     uint64_t request_id = ictx->async_request_seq.inc();
     int r;
     do {
-      C_SaferCond *ctx;
+      C_SaferCond ctx;
       {
        RWLock::RLocker l(ictx->owner_lock);
        while (ictx->image_watcher->is_lock_supported()) {
@@ -1639,15 +1639,13 @@ reprotect_and_return_err:
          ldout(ictx->cct, 5) << "resize timed out notifying lock owner" << dendl;
        }
 
-       ctx = new C_SaferCond();
-       r = async_resize(ictx, ctx, size, prog_ctx);
+       r = async_resize(ictx, &ctx, size, prog_ctx);
        if (r < 0) {
-         delete ctx;
          return r;
        }
       }
 
-      r = ctx->wait();
+      r = ctx.wait();
       if (r == -ERESTART) {
        ldout(ictx->cct, 5) << "resize interrupted: restarting" << dendl;
       }
@@ -2118,10 +2116,10 @@ reprotect_and_return_err:
 
     ldout(cct, 2) << "resizing to snapshot size..." << dendl;
     NoOpProgressContext no_op;
-    C_SaferCond *ctx = new C_SaferCond();
-    async_resize_helper(ictx, ctx, original_size, new_size, no_op);
+    C_SaferCond ctx;
+    async_resize_helper(ictx, &ctx, original_size, new_size, no_op);
 
-    r = ctx->wait();
+    r = ctx.wait();
     if (r < 0) {
       lderr(cct) << "Error resizing to snapshot size: "
                 << cpp_strerror(r) << dendl;
@@ -2460,7 +2458,7 @@ reprotect_and_return_err:
     uint64_t request_id = ictx->async_request_seq.inc();
     int r;
     do {
-      C_SaferCond *ctx;
+      C_SaferCond ctx;
       {
         RWLock::RLocker l(ictx->owner_lock);
         while (ictx->image_watcher->is_lock_supported()) {
@@ -2478,15 +2476,13 @@ reprotect_and_return_err:
           ldout(ictx->cct, 5) << "flatten timed out notifying lock owner" << dendl;
         }
 
-       ctx = new C_SaferCond();
-        r = async_flatten(ictx, ctx, prog_ctx);
+        r = async_flatten(ictx, &ctx, prog_ctx);
         if (r < 0) {
-         delete ctx;
          return r;
         }
       }
 
-      r = ctx->wait();
+      r = ctx.wait();
       if (r == -ERESTART) {
        ldout(ictx->cct, 5) << "flatten interrupted: restarting" << dendl;
       }