Skip to contentSkip to conversation

main - cmdlib_lvm2_init: release cmd on failure path

PATCH Zdenek Kabelac 1 participant 1 message Sep 13, 2021

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b36ab8a0639e85a5674a83808ccbb526a7191699
Commit:        b36ab8a0639e85a5674a83808ccbb526a7191699
Parent:        cd897e536fb69281d5d8e3e382a3827640913bd1
Author:        Wu Guanghao <[email protected]>
AuthorDate:    Mon Aug 30 15:13:00 2021 +0800
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Sep 13 12:34:41 2021 +0200

cmdlib_lvm2_init: release cmd on failure path

The cmd memory space is allocated by zalloc, and the registration fails and is not released.

Although this code would be ever triggered just in the case of some internal (likely compilation) bug.

---
 tools/lvmcmdlib.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/lvmcmdlib.c +3 -1
index 152d176b2..6b326893c 100644
@@ -33,8 +33,10 @@ void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded)
 	if (!(cmd = init_lvm(1, 1, threaded)))
 		return NULL;
 
-	if (!lvm_register_commands(cmd, NULL))
+	if (!lvm_register_commands(cmd, NULL)) {
+		free(cmd);
 		return NULL;
+	}
 
 	return (void *) cmd;
 }