From 09a306d6528581a4f3ecbeedf315108f99c872c3 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Mon, 26 May 2025 17:57:34 +0200
Subject: [PATCH] libmount: (verity) fix deinitialization
Fixes: https://github.com/util-linux/util-linux/issues/3592
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/hook_veritydev.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
@@ -180,9 +180,13 @@ static struct hookset_data *new_hookset_data(
struct libmnt_context *cxt,
const struct libmnt_hookset *hs)
{
- struct hookset_data *hsd = calloc(1, sizeof(struct hookset_data));
+ struct hookset_data *hsd;
+
+ hsd = calloc(1, sizeof(struct hookset_data));
+ if (!hsd)
+ return NULL;
- if (hsd && mnt_context_set_hookset_data(cxt, hs, hsd) != 0)
+ if (mnt_context_set_hookset_data(cxt, hs, hsd) != 0)
goto failed;
#ifdef CRYPTSETUP_VIA_DLOPEN
@@ -196,7 +200,10 @@ static struct hookset_data *new_hookset_data(
return hsd;
failed:
- free(hsd);
+ if (mnt_context_get_hookset_data(cxt, hs))
+ free_hookset_data(cxt, hs);
+ else
+ free(hsd);
return NULL;
}