]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
IoCtxImpl: delete WatchCtx when it's internal alloc 7830/head
authorHaomai Wang <haomai@xsky.com>
Sat, 27 Feb 2016 05:42:57 +0000 (13:42 +0800)
committerHaomai Wang <haomai@xsky.com>
Sun, 28 Feb 2016 04:50:56 +0000 (12:50 +0800)
Fix #14907
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/librados/IoCtxImpl.cc
src/librados/IoCtxImpl.h
src/librados/librados.cc

index f5f47b4447537e88a2211880e77718941225206a..229b47b4466d1b625ca8e7a40a9b95e30c72b79d 100644 (file)
@@ -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);
index f0eb2580eec890d6070d46f4ed7eb188f90b3d84..f8e08ad5295076d76c86a2602a426eeed4c38f04 100644 (file)
@@ -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);
index f9931e8b325e7b95322b5ef5d542bdb09a2aa697..6b2f348dd5e1a3b00c595337319766770150cc55 100644 (file)
@@ -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<librados::AioCompletionImpl*>(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;