From: Jason Dillaman Date: Thu, 26 Feb 2015 21:58:07 +0000 (-0500) Subject: librbd: C_SaferCond memory leak X-Git-Tag: v0.94~69^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2c666f3aba3febca2e0e252a535c4136d459b891;p=ceph.git librbd: C_SaferCond memory leak 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 --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 24ef4156cf71..e2e90d2745a6 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -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) { diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 7fa201230ee0..cdf3f9bc5124 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -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; }