From 34bde8b6c7e517239a05334683a09f2b5075fdcc Mon Sep 17 00:00:00 2001
From: Zdenek Kabelac <zkabelac@redhat.com>
Date: Fri, 8 Nov 2019 12:51:48 +0100
Subject: [PATCH 171/180] lvmcache: free resource on error path

Free allocated svg on error path.
Also explicitely ignore dm_strncpy() result.
(We know it will end with failure here.)
---
 lib/cache/lvmcache.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 9890325..c12ec2b 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -325,10 +325,12 @@ void lvmcache_save_vg(struct volume_group *vg, int precommitted)
 
 		dm_list_init(&svg->saved_vg_to_free);
 
-		dm_strncpy(svg->vgid, (const char *)vg->id.uuid, sizeof(svg->vgid));
+		/* Ignore result code, size we intentionally short-cut & pad with 0 */
+		(void) dm_strncpy(svg->vgid, (const char *)vg->id.uuid, sizeof(svg->vgid));
 
 		if (!dm_hash_insert(_saved_vg_hash, svg->vgid, svg)) {
 			log_error("lvmcache: failed to insert saved_vg %s", svg->vgid);
+			dm_free(svg);
 			return;
 		}
 	} else {
-- 
1.8.3.1

