rbd: fix image id leak in initial probe
authorAlex Elder <elder@inktank.com>
Fri, 26 Apr 2013 04:15:08 +0000 (23:15 -0500)
committerSage Weil <sage@inktank.com>
Thu, 2 May 2013 04:19:34 +0000 (21:19 -0700)
If a format 2 image id is found for an image being mapped, but the
subsequent probe of the image fails, rbd_dev_probe() quits without
freeing the image id.  Fix that.

Also drop a redundant hunk of code in rbd_dev_image_id().

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
drivers/block/rbd.c

index 0ddcbe584a1f8b6e0535f814e9e3f16ffd936635..815c174661a82a1ba2d03eab6ad973c45c102ef4 100644 (file)
@@ -4800,16 +4800,20 @@ static int rbd_dev_probe(struct rbd_device *rbd_dev)
                ret = rbd_dev_v1_probe(rbd_dev);
        else
                ret = rbd_dev_v2_probe(rbd_dev);
-       if (ret) {
-               dout("probe failed, returning %d\n", ret);
-
-               return ret;
-       }
+       if (ret)
+               goto out_err;
 
        ret = rbd_dev_probe_finish(rbd_dev);
        if (ret)
                rbd_header_free(&rbd_dev->header);
 
+       return ret;
+out_err:
+       kfree(rbd_dev->spec->image_id);
+       rbd_dev->spec->image_id = NULL;
+
+       dout("probe failed, returning %d\n", ret);
+
        return ret;
 }