From: Kirill Shchetiniuk <[email protected]> Use the automemory management for the master key, use the virSecureErase for safe clear of the key in case of error.
Signed-off-by: Kirill Shchetiniuk <[email protected]> --- src/qemu/qemu_domain.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ac56fc7cb4..c788eb3e2a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -566,7 +566,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) { g_autofree char *path = NULL; int fd = -1; - uint8_t *masterKey = NULL; + g_autofree uint8_t *masterKey = NULL; ssize_t masterKeyLen = 0; if (!(path = qemuDomainGetMasterKeyFilePath(priv->libDir))) @@ -601,7 +601,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) masterKey = g_renew(uint8_t, masterKey, masterKeyLen); - priv->masterKey = masterKey; + priv->masterKey = g_steal_pointer(&masterKey); priv->masterKeyLen = masterKeyLen; VIR_FORCE_CLOSE(fd); @@ -609,9 +609,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) return 0; error: - if (masterKeyLen > 0) - memset(masterKey, 0, masterKeyLen); - VIR_FREE(masterKey); + virSecureErase(masterKey, masterKeyLen); VIR_FORCE_CLOSE(fd); -- 2.49.0
