From: yangjun Date: Sun, 8 Dec 2019 01:09:53 +0000 (+0800) Subject: librbd: fix rbd_open_by_id, rbd_open_by_id_read_only X-Git-Tag: v15.1.0~602^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=3457192c24a66ba499a7c9b1747bc29c79b34636;p=ceph-ci.git librbd: fix rbd_open_by_id, rbd_open_by_id_read_only These methods incorrectly delete ImageCtx on error, resulting in double-free heap corruption. Fixes: https://tracker.ceph.com/issues/43178 Signed-off-by: yangjun --- diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 0b8db4ff8b7..680b2406437 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -4434,9 +4434,7 @@ extern "C" int rbd_open_by_id(rados_ioctx_t p, const char *id, ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only); int r = ictx->state->open(0); - if (r < 0) { - delete ictx; - } else { + if (r >= 0) { *image = (rbd_image_t)ictx; } tracepoint(librbd, open_image_exit, r); @@ -4509,9 +4507,7 @@ extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p, const char *id, ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only); int r = ictx->state->open(0); - if (r < 0) { - delete ictx; - } else { + if (r >= 0) { *image = (rbd_image_t)ictx; } tracepoint(librbd, open_image_exit, r);