[PATCH 4/9] util: Fix memory leak in virPCIProbeStubDriver

John Ferlan posted 9 patches 4 years, 5 months ago
[PATCH 4/9] util: Fix memory leak in virPCIProbeStubDriver
Posted by John Ferlan 4 years, 5 months ago
Since 9ea90206, @drvpath could be overwritten if we jumped to recheck

Found by Coverity.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/util/virpci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index 6c7e6bbcab..16936c4be9 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1018,6 +1018,7 @@ virPCIProbeStubDriver(virPCIStubDriver driver)
             goto cleanup;
         }
 
+        g_free(drvpath);
         goto recheck;
     }
 
-- 
2.25.4

Re: [PATCH 4/9] util: Fix memory leak in virPCIProbeStubDriver
Posted by Peter Krempa 4 years, 5 months ago
On Tue, Jun 16, 2020 at 08:07:05 -0400, John Ferlan wrote:
> Since 9ea90206, @drvpath could be overwritten if we jumped to recheck
> 
> Found by Coverity.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/util/virpci.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/util/virpci.c b/src/util/virpci.c
> index 6c7e6bbcab..16936c4be9 100644
> --- a/src/util/virpci.c
> +++ b/src/util/virpci.c
> @@ -1018,6 +1018,7 @@ virPCIProbeStubDriver(virPCIStubDriver driver)
>              goto cleanup;
>          }
>  
> +        g_free(drvpath);

The variable is reused so please use VIR_FREE as g_free doesn't clear
the pointer.

>          goto recheck;
>      }
>  
> -- 
> 2.25.4
>