Skip to contentSkip to conversation

Btrfs-progs: subvol_uuid_search: Return error code on memory allocation failure

PATCH Superseded Prasanth K S R 2 participants 2 messages Oct 5, 2016 – Oct 6, 2016 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs: subvol_uuid_search: Return error code on memory allocation failure

From: Prasanth K S R <[email protected]>

This commit fixes coverity defect CID 1328695.

---
 send-utils.c | 5 +++++
 1 file changed, 5 insertions(+)
send-utils.c +5 -0
index a85fa08..6f80b6f 100644
@@ -486,6 +486,11 @@ struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
 		info->path = strdup(path);
 	} else {
 		info->path = malloc(PATH_MAX);
+		if (!info->path) {
+			fprintf(stderr, "Memory allocation failed\n");
+			ret = -ENOMEM;
+			goto out;
+		}
 		ret = btrfs_subvolid_resolve(s->mnt_fd, info->path,
 					     PATH_MAX, root_id);
 	}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 14 lines · Prasanth K S R

From: Prasanth K S R <[email protected]>

This commit fixes coverity defect CID 1328695.

---
 send-utils.c | 5 +++++
 1 file changed, 5 insertions(+)
send-utils.c +0 -0
index a85fa08..6f80b6f 100644

send-utils.c struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s, · line 490

Quoted 5 lines
send-utils.c +2 -0
@@ -486,6 +486,11 @@ struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
 		info->path = strdup(path);
 	} else {
 		info->path = malloc(PATH_MAX);
+		if (!info->path) {
+			fprintf(stderr, "Memory allocation failed\n");

Please use the error() helper (does not need \n terminated string).

Also, would be grat to convert subvol_uuid_search to return ERR_PTR style value (which means to conver all callers). Now we don't see why exactly it fails and interpret it as nonexistence of the uuid.