• Shaohua Li's avatar
    raid5: fix memory leak of bio integrity data · 5f9d1fde
    Shaohua Li authored
    Yi reported a memory leak of raid5 with DIF/DIX enabled disks. raid5
    doesn't alloc/free bio, instead it reuses bios. There are two issues in
    current code:
    1. the code calls bio_init (from
    init_stripe->raid5_build_block->bio_init) then bio_reset (ops_run_io).
    The bio is reused, so likely there is integrity data attached. bio_init
    will clear a pointer to integrity data and makes bio_reset can't release
    the data
    2. bio_reset is called before dispatching bio. After bio is finished,
    it's possible we don't free bio's integrity data (eg, we don't call
    bio_reset again)
    Both issues will cause memory leak. The patch moves bio_init to stripe
    creation and bio_reset to bio end io. This will fix the two issues.
    Reported-by: default avatarYi Zhang <yizhan@redhat.com>
    Signed-off-by: default avatarShaohua Li <shli@fb.com>
    5f9d1fde
raid5.c 225 KB