[PATCH v2] utils/module: fix memleak in module_load()

Dmitry Frolov posted 1 patch 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260630110601.736019-1-frolov@swemel.ru
util/module.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] utils/module: fix memleak in module_load()
Posted by Dmitry Frolov 3 weeks, 5 days ago
Memory for version_dir, allocated by g_strdup, is not freed

Found by Linux Verification Center (linuxtesting.org) with SVACE.

v1: fix with g_free()
v2: fix with g_autofree

Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
---
 util/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/module.c b/util/module.c
index 09dc43f51e..8f8e6994f1 100644
--- a/util/module.c
+++ b/util/module.c
@@ -203,7 +203,7 @@ int module_load(const char *prefix, const char *name, Error **errp)
 {
     int rv = -1;
 #ifdef CONFIG_MODULE_UPGRADES
-    char *version_dir;
+    g_autofree char *version_dir = NULL;
 #endif
     const char *search_dir;
     char *dirs[5];
-- 
2.34.1
Re: [PATCH v2] utils/module: fix memleak in module_load()
Posted by Marc-André Lureau 3 weeks, 4 days ago
On Tue, Jun 30, 2026 at 3:07 PM Dmitry Frolov <frolov@swemel.ru> wrote:
>
> Memory for version_dir, allocated by g_strdup, is not freed
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> v1: fix with g_free()
> v2: fix with g_autofree
>
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>

either way
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  util/module.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/module.c b/util/module.c
> index 09dc43f51e..8f8e6994f1 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -203,7 +203,7 @@ int module_load(const char *prefix, const char *name, Error **errp)
>  {
>      int rv = -1;
>  #ifdef CONFIG_MODULE_UPGRADES
> -    char *version_dir;
> +    g_autofree char *version_dir = NULL;
>  #endif
>      const char *search_dir;
>      char *dirs[5];
> --
> 2.34.1
>
>