*/
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, false);
        if (ret) {
-               ulist_free(old_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
        if (ret) {
                ulist_free(old_roots);
-               ulist_free(new_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
                return ret;
        }
 
+       /* btrfs_qgroup_account_extent() always frees the ulists passed to it. */
+       old_roots = NULL;
+       new_roots = NULL;
+
        if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
                                nodesize, nodesize)) {
                test_err("qgroup counts didn't match expected values");
                return -EINVAL;
        }
-       old_roots = NULL;
-       new_roots = NULL;
 
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, false);
        if (ret) {
-               ulist_free(old_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
        if (ret) {
                ulist_free(old_roots);
-               ulist_free(new_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
 
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, false);
        if (ret) {
-               ulist_free(old_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
        if (ret) {
                ulist_free(old_roots);
-               ulist_free(new_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
 
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, false);
        if (ret) {
-               ulist_free(old_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
        if (ret) {
                ulist_free(old_roots);
-               ulist_free(new_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
 
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots, false);
        if (ret) {
-               ulist_free(old_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }
        ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots, false);
        if (ret) {
                ulist_free(old_roots);
-               ulist_free(new_roots);
                test_err("couldn't find old roots: %d", ret);
                return ret;
        }