dm: fix dm_target_io leak if clone_bio() returns an error
authorMikulas Patocka <mpatocka@redhat.com>
Sat, 9 Apr 2016 16:48:18 +0000 (12:48 -0400)
committerMike Snitzer <snitzer@redhat.com>
Mon, 11 Apr 2016 15:49:09 +0000 (11:49 -0400)
Commit c80914e81ec5b08 ("dm: return error if bio_integrity_clone() fails
in clone_bio()") changed clone_bio() such that if it does return error
then the alloc_tio() created resources (both the bio that was allocated
to be a clone and the containing dm_target_io struct) will leak.

Fix this by calling free_tio() in __clone_and_map_data_bio()'s
clone_bio() error path.

Fixes: c80914e81ec5b08 ("dm: return error if bio_integrity_clone() fails in clone_bio()")
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm.c

index be4905769a45637a4882af087544578cdb90efa4..3d3ac13287a4570847ae179a483fe13586e96f66 100644 (file)
@@ -1662,8 +1662,10 @@ static int __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,
                tio = alloc_tio(ci, ti, target_bio_nr);
                tio->len_ptr = len;
                r = clone_bio(tio, bio, sector, *len);
-               if (r < 0)
+               if (r < 0) {
+                       free_tio(ci->md, tio);
                        break;
+               }
                __map_bio(tio);
        }