When btrfs_check_super() or add_sys_array() failed, the buffer is not
released and the pthread mutex is still locked.
Fix it by adding a new out label, to release the buffer, unlock the
mutex and return the error code.
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
ret = btrfs_check_super(super, 0);
if (ret < 0) {
error("invalid superblock");
- return ret;
+ goto out;
}
ret = add_sys_array(mdres, super);
if (ret < 0) {
error("failed to read system chunk array");
- free(buffer);
- pthread_mutex_unlock(&mdres->mutex);
- return ret;
+ goto out;
}
mdres->nodesize = btrfs_super_nodesize(super);
if (btrfs_super_incompat_flags(super) &
memcpy(mdres->uuid, super->dev_item.uuid, BTRFS_UUID_SIZE);
mdres->devid = get_unaligned_le64(&super->dev_item.devid);
+out:
free(buffer);
pthread_mutex_unlock(&mdres->mutex);
+ if (ret < 0)
+ return ret;
return search_for_chunk_blocks(mdres);
}