[PATCH] spapr: Fix memory leak in h_client_architecture_support()

Greg Kurz posted 1 patch 4 years, 1 month ago
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test checkpatch passed
Test FreeBSD passed
Test asan passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/158481206205.336182.16106097429336044843.stgit@bahia.lan
Maintainers: David Gibson <david@gibson.dropbear.id.au>
hw/ppc/spapr_hcall.c |    1 +
1 file changed, 1 insertion(+)
[PATCH] spapr: Fix memory leak in h_client_architecture_support()
Posted by Greg Kurz 4 years, 1 month ago
This is the only error path that needs to free the previously allocated
ov1.

Reported-by: Coverity (CID 1421924)
Fixes: cbd0d7f36322 "spapr: Fail CAS if option vector table cannot be parsed"
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr_hcall.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 40c86e91eb89..0d50fc911790 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1726,6 +1726,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
     }
     ov5_guest = spapr_ovec_parse_vector(ov_table, 5);
     if (!ov5_guest) {
+        spapr_ovec_cleanup(ov1_guest);
         warn_report("guest didn't provide option vector 5");
         return H_PARAMETER;
     }


Re: [PATCH] spapr: Fix memory leak in h_client_architecture_support()
Posted by Philippe Mathieu-Daudé 4 years, 1 month ago
On 3/21/20 6:34 PM, Greg Kurz wrote:
> This is the only error path that needs to free the previously allocated
> ov1.
> 
> Reported-by: Coverity (CID 1421924)
> Fixes: cbd0d7f36322 "spapr: Fail CAS if option vector table cannot be parsed"
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>   hw/ppc/spapr_hcall.c |    1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> index 40c86e91eb89..0d50fc911790 100644
> --- a/hw/ppc/spapr_hcall.c
> +++ b/hw/ppc/spapr_hcall.c
> @@ -1726,6 +1726,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
>       }
>       ov5_guest = spapr_ovec_parse_vector(ov_table, 5);
>       if (!ov5_guest) {
> +        spapr_ovec_cleanup(ov1_guest);

Quicker than using g_autoptr(), so for 5.0:

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>           warn_report("guest didn't provide option vector 5");
>           return H_PARAMETER;
>       }
> 


Re: [PATCH] spapr: Fix memory leak in h_client_architecture_support()
Posted by David Gibson 4 years, 1 month ago
On Sat, Mar 21, 2020 at 06:34:22PM +0100, Greg Kurz wrote:
> This is the only error path that needs to free the previously allocated
> ov1.
> 
> Reported-by: Coverity (CID 1421924)
> Fixes: cbd0d7f36322 "spapr: Fail CAS if option vector table cannot be parsed"
> Signed-off-by: Greg Kurz <groug@kaod.org>

Applied to ppc-forr-5.0.

> ---
>  hw/ppc/spapr_hcall.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> index 40c86e91eb89..0d50fc911790 100644
> --- a/hw/ppc/spapr_hcall.c
> +++ b/hw/ppc/spapr_hcall.c
> @@ -1726,6 +1726,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
>      }
>      ov5_guest = spapr_ovec_parse_vector(ov_table, 5);
>      if (!ov5_guest) {
> +        spapr_ovec_cleanup(ov1_guest);
>          warn_report("guest didn't provide option vector 5");
>          return H_PARAMETER;
>      }
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson