Skip to content

Commit

Permalink
rbd: don't leak rbd_req for rbd_req_sync_notify_ack()
Browse files Browse the repository at this point in the history
When rbd_req_sync_notify_ack() calls rbd_do_request() it supplies
rbd_simple_req_cb() as its callback function.  Because the callback
is supplied, an rbd_req structure gets allocated and populated so it
can be used by the callback.  However rbd_simple_req_cb() is not
freeing (or even using) the rbd_req structure, so it's getting
leaked.

Since rbd_simple_req_cb() has no need for the rbd_req structure,
just avoid allocating one for this case.  Of the three calls to
rbd_do_request(), only the one from rbd_do_op() needs the rbd_req
structure, and that call can be distinguished from the other two
because it supplies a non-null rbd_collection pointer.

So fix this leak by only allocating the rbd_req structure if a
non-null "coll" value is provided to rbd_do_request().

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
  • Loading branch information
Alex Elder committed Jan 17, 2013
1 parent 2e53c6c commit 1821665
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ static int rbd_do_request(struct request *rq,
bio_get(osd_req->r_bio);
}

if (rbd_cb) {
if (coll) {
ret = -ENOMEM;
rbd_req = kmalloc(sizeof(*rbd_req), GFP_NOIO);
if (!rbd_req)
Expand All @@ -1146,7 +1146,7 @@ static int rbd_do_request(struct request *rq,
rbd_req->pages = pages;
rbd_req->len = len;
rbd_req->coll = coll;
rbd_req->coll_index = coll ? coll_index : 0;
rbd_req->coll_index = coll_index;
}

osd_req->r_callback = rbd_cb;
Expand Down

0 comments on commit 1821665

Please sign in to comment.