target/i386: Fix memory leak in sev_read_file_base64()
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 20 Aug 2021 16:56:50 +0000 (17:56 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 30 Sep 2021 13:30:24 +0000 (15:30 +0200)
commit523a3d9524d5edd49dbec50c634b6e3872ad7d84
tree945754379a3bd477fa54f0346eb0f6be9be0ddf3
parent809954efc279deff281ffad3d6a888760ea2b2d9
target/i386: Fix memory leak in sev_read_file_base64()

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