[lvm-devel] master - cov: dmstats check for failing malloc

Zdenek Kabelac zkabelac at sourceware.org
Mon Oct 15 15:55:17 UTC 2018


Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b7121226258f7dfe759cc1f8625cbfb80fec161
Commit:        9b7121226258f7dfe759cc1f8625cbfb80fec161
Parent:        30b1b575067bcab27ab1788247754b183387f55e
Author:        Zdenek Kabelac <zkabelac at redhat.com>
AuthorDate:    Mon Oct 15 14:58:24 2018 +0200
Committer:     Zdenek Kabelac <zkabelac at redhat.com>
CommitterDate: Mon Oct 15 17:49:44 2018 +0200

cov: dmstats check for failing malloc

Add missing check for allocation success.
---
 libdm/dm-tools/dmsetup.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index fb1a574..835fdcd 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -5224,7 +5224,10 @@ static int _do_stats_create_regions(struct dm_stats *dms,
 	if (!segments || (info.target_count == 1))
 		region_ids = &region_id;
 	else
-		region_ids = malloc(info.target_count * sizeof(*region_ids));
+		if (!(region_ids = malloc(info.target_count * sizeof(*region_ids)))) {
+			log_error("Failed to allocated region IDs.");
+			goto out;
+		}
 
 	do {
 		uint64_t segment_start, segment_len;




More information about the lvm-devel mailing list