* [PATCH] target/i386: Fix memory leak in sev_read_file_base64()
@ 2021-08-20 16:56 Peter Maydell
2021-08-20 17:05 ` Philippe Mathieu-Daudé
2021-09-13 12:33 ` Peter Maydell
0 siblings, 2 replies; 4+ messages in thread
From: Peter Maydell @ 2021-08-20 16:56 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Brijesh Singh
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>
---
Tested with 'make/make check' only...
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 83df8c09f6a..1e7833da1ab 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.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] target/i386: Fix memory leak in sev_read_file_base64()
2021-08-20 16:56 [PATCH] target/i386: Fix memory leak in sev_read_file_base64() Peter Maydell
@ 2021-08-20 17:05 ` Philippe Mathieu-Daudé
2021-09-20 12:56 ` Paolo Bonzini
2021-09-13 12:33 ` Peter Maydell
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-20 17:05 UTC (permalink / raw)
To: Peter Maydell, qemu-devel
Cc: Paolo Bonzini, Li Qiang, Brijesh Singh, Pan Nengyuan
On 8/20/21 6:56 PM, Peter Maydell wrote:
> 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>
> ---
> Tested with 'make/make check' only...
>
> target/i386/sev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] target/i386: Fix memory leak in sev_read_file_base64()
2021-08-20 16:56 [PATCH] target/i386: Fix memory leak in sev_read_file_base64() Peter Maydell
2021-08-20 17:05 ` Philippe Mathieu-Daudé
@ 2021-09-13 12:33 ` Peter Maydell
1 sibling, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2021-09-13 12:33 UTC (permalink / raw)
To: QEMU Developers; +Cc: Paolo Bonzini, Brijesh Singh
Ping?
thanks
-- PMM
On Fri, 20 Aug 2021 at 17:56, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> 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>
> ---
> Tested with 'make/make check' only...
>
> 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 83df8c09f6a..1e7833da1ab 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.20.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] target/i386: Fix memory leak in sev_read_file_base64()
2021-08-20 17:05 ` Philippe Mathieu-Daudé
@ 2021-09-20 12:56 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-09-20 12:56 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, Peter Maydell, qemu-devel
Cc: Pan Nengyuan, Li Qiang, Brijesh Singh
On 20/08/21 19:05, Philippe Mathieu-Daudé wrote:
> On 8/20/21 6:56 PM, Peter Maydell wrote:
>> 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>
>> ---
>> Tested with 'make/make check' only...
>>
>> target/i386/sev.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-20 12:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 16:56 [PATCH] target/i386: Fix memory leak in sev_read_file_base64() Peter Maydell
2021-08-20 17:05 ` Philippe Mathieu-Daudé
2021-09-20 12:56 ` Paolo Bonzini
2021-09-13 12:33 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).