diff --git a/tools/lvmcmdlib.c b/tools/lvmcmdlib.c
index 152d176b2..6b326893c 100644
--- a/tools/lvmcmdlib.c
+++ b/tools/lvmcmdlib.c
@@ -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;
 }