[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 29/33] target/i386: Fix memory leak in sev_read_file_base64()
From: |
Paolo Bonzini |
Subject: |
[PULL 29/33] target/i386: Fix memory leak in sev_read_file_base64() |
Date: |
Tue, 28 Sep 2021 14:51:12 +0200 |
From: Peter Maydell <peter.maydell@linaro.org>
In sev_read_file_base64() we call g_file_get_contents(), which
allocates memory for the file contents. We then base64-decode the
contents (which allocates another buffer for the decoded data), but
forgot to free the memory for the original file data.
Use g_autofree to ensure that the file data is freed.
Fixes: Coverity CID 1459997
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20210820165650.2839-1-peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/sev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 0b2c8f594a..fa7210473a 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -565,7 +565,7 @@ static int
sev_read_file_base64(const char *filename, guchar **data, gsize *len)
{
gsize sz;
- gchar *base64;
+ g_autofree gchar *base64 = NULL;
GError *error = NULL;
if (!g_file_get_contents(filename, &base64, &sz, &error)) {
--
2.31.1
- [PULL 31/33] memory: Add tracepoint for dirty sync, (continued)
- [PULL 31/33] memory: Add tracepoint for dirty sync, Paolo Bonzini, 2021/09/28
- [PULL 28/33] tests: qtest: bios-tables-test depends on the unpacked edk2 ROMs, Paolo Bonzini, 2021/09/28
- [PULL 33/33] meson_options.txt: Switch the default value for the vnc option to 'auto', Paolo Bonzini, 2021/09/28
- [PULL 02/33] Kconfig: Add CONFIG_SGX support, Paolo Bonzini, 2021/09/28
- [PULL 05/33] i386: Add 'sgx-epc' device to expose EPC sections to guest, Paolo Bonzini, 2021/09/28
- [PULL 15/33] i386: Propagate SGX CPUID sub-leafs to KVM, Paolo Bonzini, 2021/09/28
- [PULL 18/33] hw/i386/pc: Account for SGX EPC sections when calculating device memory, Paolo Bonzini, 2021/09/28
- [PULL 17/33] hw/i386/fw_cfg: Set SGX bits in feature control fw_cfg accordingly, Paolo Bonzini, 2021/09/28
- [PULL 20/33] i386: acpi: Add SGX EPC entry to ACPI tables, Paolo Bonzini, 2021/09/28
- [PULL 19/33] i386/pc: Add e820 entry for SGX EPC section(s), Paolo Bonzini, 2021/09/28
- [PULL 29/33] target/i386: Fix memory leak in sev_read_file_base64(),
Paolo Bonzini <=
- [PULL 03/33] hostmem: Add hostmem-epc as a backend for SGX EPC, Paolo Bonzini, 2021/09/28
- [PULL 21/33] q35: Add support for SGX EPC, Paolo Bonzini, 2021/09/28
- [PULL 23/33] sgx-epc: Add the fill_device_info() callback support, Paolo Bonzini, 2021/09/28
- [PULL 27/33] meson: unpack edk2 firmware even if --disable-blobs, Paolo Bonzini, 2021/09/28
- [PULL 24/33] docs/system: Add SGX documentation to the system manual, Paolo Bonzini, 2021/09/28
- [PULL 30/33] memory: Name all the memory listeners, Paolo Bonzini, 2021/09/28
- [PULL 32/33] build-sys: add HAVE_IPPROTO_MPTCP, Paolo Bonzini, 2021/09/28
- [PULL 25/33] target/i386: Add HMP and QMP interfaces for SGX, Paolo Bonzini, 2021/09/28
- Re: [PULL 00/33] x86 and misc changes for 2021-09-28, Peter Maydell, 2021/09/29