gkostka / lwext4

ext2/ext3/ext4 filesystem library for microcontrollers
http://sourceforge.net/projects/lwext4/
Other
491 stars 128 forks source link

ext4_fs_put_block_group_ref missing in early returns. #57

Open wzx-ipads opened 2 years ago

wzx-ipads commented 2 years ago

In int ext4_balloc_alloc_block(), ext4_fs_put_block_group_ref() should be called in early returns in line#440 and line#455.


        /* Try to find free block near to goal */
    uint32_t tmp_idx;
    for (tmp_idx = idx_in_bg + 1; tmp_idx < end_idx; ++tmp_idx) {
        if (ext4_bmap_is_bit_clr(b.data, tmp_idx)) {
            ext4_bmap_bit_set(b.data, tmp_idx);

            ext4_balloc_set_bitmap_csum(sb, bg, b.data);
            ext4_trans_set_block_dirty(b.buf);
            r = ext4_block_set(inode_ref->fs->bdev, &b);
            if (r != EOK)
                return r;

            alloc = ext4_fs_bg_idx_to_addr(sb, tmp_idx, bg_id);
            goto success;
        }
    }

        /* Find free bit in bitmap */
    r = ext4_bmap_bit_find_clr(b.data, idx_in_bg, blk_in_bg, &rel_blk_idx);
    if (r == EOK) {
        ext4_bmap_bit_set(b.data, rel_blk_idx);
        ext4_balloc_set_bitmap_csum(sb, bg_ref.block_group, b.data);
        ext4_trans_set_block_dirty(b.buf);
        r = ext4_block_set(inode_ref->fs->bdev, &b);
        if (r != EOK)
            return r;

        alloc = ext4_fs_bg_idx_to_addr(sb, rel_blk_idx, bg_id);
        goto success;
    }