Skip to contentSkip to conversation

Btrfs progs, coverity fixes for 3.18-rc3

PATCH New David Sterba 1 participant 6 messages Dec 30, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover Btrfs progs, coverity fixes for 3.18-rc3

Several issues reported by coverity, minor resource leaks and two bugfixes.

David Sterba (5):
btrfs-progs: check, fix path leak in error branch
btrfs-progs: fi show, don't leak canonical path
btrfs-progs: check, missing parens around compound block in
find_normal_file_extent
btrfs-progs: fix overflow check in btrfs_insert_inode_ref
btrfs-progs: fix minor leak of dev_info in btrfs_scan_kernel

 cmds-check.c      | 8 +++++---
 cmds-filesystem.c | 6 ++++--
 inode-item.c      | 2 +-
 3 files changed, 10 insertions(+), 6 deletions(-)
Signature · 1 line
2.1.3
#1 lore raw

PATCH 1/5 btrfs-progs: check, fix path leak in error branch

Resolves-coverity-id: 1260250

---
 cmds-check.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
cmds-check.c +3 -2
index e74b116c0c43..71e4f4f3a13b 100644
@@ -2839,7 +2839,7 @@ static int repair_btree(struct btrfs_root *root,
 		ret = PTR_ERR(trans);
 		fprintf(stderr, "Error starting transaction: %s\n",
 			strerror(-ret));
-		return ret;
+		goto out_free_path;
 	}
 	cache = first_cache_extent(corrupt_blocks);
 	while (cache) {
@@ -2894,8 +2894,9 @@ static int repair_btree(struct btrfs_root *root,
 		cache = next_cache_extent(cache);
 	}
 out:
-	btrfs_free_path(path);
 	btrfs_commit_transaction(trans, root);
+out_free_path:
+	btrfs_free_path(path);
 	return ret;
 }
 
Signature · 1 line
2.1.3
#2 lore raw

PATCH 2/5 btrfs-progs: fi show, don't leak canonical path

In reply to David Sterba

Resolves-coverity-id: 1260252

---
 cmds-filesystem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmds-filesystem.c +1 -1
index 80875fffddfe..1c1d34ae8ca2 100644
@@ -471,7 +471,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
 		char *canonical_path;
 
 		tmp_dev_info = (struct btrfs_ioctl_dev_info_args *)&dev_info[i];
-		canonical_path = canonicalize_path((char *)tmp_dev_info->path);
 
 		/* Add check for missing devices even mounted */
 		fd = open((char *)tmp_dev_info->path, O_RDONLY);
@@ -480,6 +479,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
 			continue;
 		}
 		close(fd);
+		canonical_path = canonicalize_path((char *)tmp_dev_info->path);
 		printf("\tdevid %4llu size %s used %s path %s\n",
 			tmp_dev_info->devid,
 			pretty_size(tmp_dev_info->total_bytes),
Signature · 1 line
2.1.3
#3 lore raw

PATCH 3/5 btrfs-progs: check, missing parens around compound block in find_normal_file_extent

In reply to David Sterba

Resolves-coverity-id: 1260248

---
 cmds-check.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
cmds-check.c +2 -1
index 71e4f4f3a13b..d2d218a88589 100644
@@ -2160,9 +2160,10 @@ static int find_normal_file_extent(struct btrfs_root *root, u64 ino)
 		fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
 				    struct btrfs_file_extent_item);
 		type = btrfs_file_extent_type(path->nodes[0], fi);
-		if (type != BTRFS_FILE_EXTENT_INLINE)
+		if (type != BTRFS_FILE_EXTENT_INLINE) {
 			ret = 1;
 			goto out;
+		}
 	}
 out:
 	btrfs_free_path(path);
Signature · 1 line
2.1.3
#4 lore raw

PATCH 4/5 btrfs-progs: fix overflow check in btrfs_insert_inode_ref

In reply to David Sterba

Resolves-coverity-id: 1260247

---
 inode-item.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
inode-item.c +1 -1
index 993f3091e335..522d25a433ac 100644
@@ -89,7 +89,7 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
 		ptr = (unsigned long)(ref + 1);
 		ret = 0;
 	} else if (ret < 0) {
-		if (ret == EOVERFLOW)
+		if (ret == -EOVERFLOW)
 			ret = -EMLINK;
 		goto out;
 	} else {
Signature · 1 line
2.1.3
#5 lore raw

PATCH 5/5 btrfs-progs: fix minor leak of dev_info in btrfs_scan_kernel

In reply to David Sterba

Resolves-coverity-id: 1127098

---
 cmds-filesystem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds-filesystem.c +3 -1
index 1c1d34ae8ca2..a3cf114fb6ac 100644
@@ -516,8 +516,10 @@ static int btrfs_scan_kernel(void *search)
 			continue;
 		ret = get_fs_info(mnt->mnt_dir, &fs_info_arg,
 				&dev_info_arg);
-		if (ret)
+		if (ret) {
+			kfree(dev_info_arg);
 			goto out;
+		}
 
 		if (get_label_mounted(mnt->mnt_dir, label)) {
 			kfree(dev_info_arg);
Signature · 1 line
2.1.3