From: Haomai Wang Date: Sat, 27 Feb 2016 05:42:57 +0000 (+0800) Subject: IoCtxImpl: delete WatchCtx when it's internal alloc X-Git-Tag: v11.0.0~797^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=65a096be8792432a56a073d131c8c51e6014288d;p=ceph.git IoCtxImpl: delete WatchCtx when it's internal alloc Fix #14907 Signed-off-by: Haomai Wang --- diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index f5f47b444753..229b47b4466d 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -1223,14 +1223,20 @@ struct WatchInfo : public Objecter::WatchContext { object_t oid; librados::WatchCtx *ctx; librados::WatchCtx2 *ctx2; + bool internal = false; WatchInfo(librados::IoCtxImpl *io, object_t o, - librados::WatchCtx *c, librados::WatchCtx2 *c2) - : ioctx(io), oid(o), ctx(c), ctx2(c2) { + librados::WatchCtx *c, librados::WatchCtx2 *c2, + bool inter) + : ioctx(io), oid(o), ctx(c), ctx2(c2), internal(inter) { ioctx->get(); } ~WatchInfo() { ioctx->put(); + if (internal) { + delete ctx; + delete ctx2; + } } void handle_notify(uint64_t notify_id, @@ -1262,10 +1268,10 @@ struct WatchInfo : public Objecter::WatchContext { } }; -int librados::IoCtxImpl::watch(const object_t& oid, - uint64_t *handle, - librados::WatchCtx *ctx, - librados::WatchCtx2 *ctx2) +int librados::IoCtxImpl::watch(const object_t& oid, uint64_t *handle, + librados::WatchCtx *ctx, + librados::WatchCtx2 *ctx2, + bool internal) { ::ObjectOperation wr; version_t objver; @@ -1274,7 +1280,7 @@ int librados::IoCtxImpl::watch(const object_t& oid, Objecter::LingerOp *linger_op = objecter->linger_register(oid, oloc, 0); *handle = linger_op->get_cookie(); linger_op->watch_context = new WatchInfo(this, - oid, ctx, ctx2); + oid, ctx, ctx2, internal); prepare_assert_ops(&wr); wr.watch(*handle, CEPH_OSD_WATCH_OP_WATCH); @@ -1300,7 +1306,8 @@ int librados::IoCtxImpl::aio_watch(const object_t& oid, AioCompletionImpl *c, uint64_t *handle, librados::WatchCtx *ctx, - librados::WatchCtx2 *ctx2) + librados::WatchCtx2 *ctx2, + bool internal) { Objecter::LingerOp *linger_op = objecter->linger_register(oid, oloc, 0); c->io = this; @@ -1310,7 +1317,7 @@ int librados::IoCtxImpl::aio_watch(const object_t& oid, version_t objver; *handle = linger_op->get_cookie(); - linger_op->watch_context = new WatchInfo(this, oid, ctx, ctx2); + linger_op->watch_context = new WatchInfo(this, oid, ctx, ctx2, internal); prepare_assert_ops(&wr); wr.watch(*handle, CEPH_OSD_WATCH_OP_WATCH); diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index f0eb2580eec8..f8e08ad52950 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -222,9 +222,10 @@ struct librados::IoCtxImpl { void set_sync_op_version(version_t ver); int watch(const object_t& oid, uint64_t *cookie, librados::WatchCtx *ctx, - librados::WatchCtx2 *ctx2); + librados::WatchCtx2 *ctx2, bool internal = false); int aio_watch(const object_t& oid, AioCompletionImpl *c, uint64_t *cookie, - librados::WatchCtx *ctx, librados::WatchCtx2 *ctx2); + librados::WatchCtx *ctx, librados::WatchCtx2 *ctx2, + bool internal = false); int watch_check(uint64_t cookie); int unwatch(uint64_t cookie); int aio_unwatch(uint64_t cookie, AioCompletionImpl *c); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index f9931e8b325e..6b2f348dd5e1 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -4369,7 +4369,7 @@ extern "C" int rados_watch(rados_ioctx_t io, const char *o, uint64_t ver, librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io; object_t oid(o); C_WatchCB *wc = new C_WatchCB(watchcb, arg); - int retval = ctx->watch(oid, cookie, wc, NULL); + int retval = ctx->watch(oid, cookie, wc, NULL, true); tracepoint(librados, rados_watch_exit, retval, *handle); return retval; } @@ -4407,7 +4407,7 @@ extern "C" int rados_watch2(rados_ioctx_t io, const char *o, uint64_t *handle, librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io; object_t oid(o); C_WatchCB2 *wc = new C_WatchCB2(watchcb, watcherrcb, arg); - ret = ctx->watch(oid, cookie, NULL, wc); + ret = ctx->watch(oid, cookie, NULL, wc, true); } tracepoint(librados, rados_watch_exit, ret, handle ? *handle : 0); return ret; @@ -4430,7 +4430,7 @@ extern "C" int rados_aio_watch(rados_ioctx_t io, const char *o, librados::AioCompletionImpl *c = reinterpret_cast(completion); C_WatchCB2 *wc = new C_WatchCB2(watchcb, watcherrcb, arg); - ret = ctx->aio_watch(oid, c, cookie, NULL, wc); + ret = ctx->aio_watch(oid, c, cookie, NULL, wc, true); } tracepoint(librados, rados_watch_exit, ret, handle ? *handle : 0); return ret;