[PATCH] 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/20260630093302.688700-1-frolov@swemel.ru
There is a newer version of this series
util/module.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] utils/module: fix memleak in module_load()
Posted by Dmitry Frolov 3 weeks, 5 days ago
Memmory for version_dir, allocated by g_strdup, is not freed

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

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

diff --git a/util/module.c b/util/module.c
index 09dc43f51e..dbca6bc8be 100644
--- a/util/module.c
+++ b/util/module.c
@@ -243,6 +243,7 @@ int module_load(const char *prefix, const char *name, Error **errp)
                              G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
                              '_');
     dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
+    g_free(version_dir);
 #endif
     assert(n_dirs <= ARRAY_SIZE(dirs));
 
-- 
2.34.1
Re: [PATCH] utils/module: fix memleak in module_load()
Posted by Marc-André Lureau 3 weeks, 5 days ago
Hi

On Tue, Jun 30, 2026 at 1:35 PM Dmitry Frolov <frolov@swemel.ru> wrote:
>
> Memmory for version_dir, allocated by g_strdup, is not freed
>

memory

> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> ---
>  util/module.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/util/module.c b/util/module.c
> index 09dc43f51e..dbca6bc8be 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -243,6 +243,7 @@ int module_load(const char *prefix, const char *name, Error **errp)
>                               G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
>                               '_');
>      dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
> +    g_free(version_dir);

Or declare the variable with g_autofree?

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

>  #endif
>      assert(n_dirs <= ARRAY_SIZE(dirs));
>
> --
> 2.34.1
>
>
[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
>
>