From: Yu Watanabe Date: Wed, 14 Sep 2022 03:21:56 +0000 (+0900) Subject: dissect-image: fix memleak on failure X-Git-Tag: v252-rc1~171^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=041e2edac8e17fc5bc4fc3b32db90b9b62d5ad0d;p=thirdparty%2Fsystemd.git dissect-image: fix memleak on failure --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index b186c3a728a..82ed55d02b7 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1964,7 +1964,7 @@ static int verity_partition( -ENODEV /* Volume is being opened but not ready, crypt_init_by_name would fail, try to open again */)) return r; if (IN_SET(r, -EEXIST, -EBUSY)) { - struct crypt_device *existing_cd = NULL; + _cleanup_(sym_crypt_freep) struct crypt_device *existing_cd = NULL; if (!restore_deferred_remove){ /* To avoid races, disable automatic removal on umount while setting up the new device. Restore it on failure. */ @@ -2014,9 +2014,8 @@ static int verity_partition( if (r < 0) return r; - if (cd) - sym_crypt_free(cd); - cd = existing_cd; + sym_crypt_free(cd); + cd = TAKE_PTR(existing_cd); } } if (r == 0)