aboutsummaryrefslogtreecommitdiff
path: root/contrib/plugins/hotpages.c
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2023-06-30 19:04:05 +0100
committerAlex Bennée <alex.bennee@linaro.org>2023-07-03 12:51:58 +0100
commit402587419993d86638f1f81fc4e55625a320ad2f (patch)
tree2eedc98308f7256c4f348aa7fe8b685045e71e21 /contrib/plugins/hotpages.c
parent6d03226b42247b68ab2f0b3663e0f624335a4055 (diff)
downloadqemu-402587419993d86638f1f81fc4e55625a320ad2f.zip
qemu-402587419993d86638f1f81fc4e55625a320ad2f.tar.gz
qemu-402587419993d86638f1f81fc4e55625a320ad2f.tar.bz2
plugins: fix memory leak while parsing options
It was hard to track down this leak as it was an internal allocation by glib and the backtraces did not give much away. The autofree was freeing the allocation with g_free() but not taking care of the individual strings. They should have been freed with g_strfreev() instead. Searching the glib source code for the correct string free function led to: G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL) and indeed if you read to the bottom of the documentation page you will find: typedef gchar** GStrv; A typedef alias for gchar**. This is mostly useful when used together with g_auto(). So fix up all the g_autofree g_strsplit case that smugly thought they had de-allocation covered. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20230630180423.558337-21-alex.bennee@linaro.org>
Diffstat (limited to 'contrib/plugins/hotpages.c')
-rw-r--r--contrib/plugins/hotpages.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/contrib/plugins/hotpages.c b/contrib/plugins/hotpages.c
index 0d12910..8316ae5 100644
--- a/contrib/plugins/hotpages.c
+++ b/contrib/plugins/hotpages.c
@@ -169,7 +169,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
for (i = 0; i < argc; i++) {
char *opt = argv[i];
- g_autofree char **tokens = g_strsplit(opt, "=", -1);
+ g_auto(GStrv) tokens = g_strsplit(opt, "=", -1);
if (g_strcmp0(tokens[0], "sortby") == 0) {
if (g_strcmp0(tokens[1], "reads") == 0) {