fuzz: Fix memory leak inside fuzz-main
Somehow I cannot create this merge request due to it being recognized as spam, despite having a verified account and being able to create fork, so I'm proposing my changes here (I also tried mailing to slirp@lists.freedesktop.org, but didn't have an answer in 10 days).
According to fuzzing/README.md and our tests there was a memory leak inside main fuzz wrapper.
The proposed patch addresses atleast the major part of the memory leak. By applying this patch, we have observed a significant improvement in fuzzing stability and runtime, allowing fuzzing processes to run for considerably longer periods without exhausting system memory.
It may be worthwhile to update the fuzzing/README.md to reflect this fix, but I was uncertain whether this should be included in the same commit or handled as a separate documentation update.
The patch is as follows:
From 1bc453a782339c4bb26f56e79f8af89785effc32 Mon Sep 17 00:00:00 2001
From: Alexander Kuznetsov <kuznetsovam@altlinux.org>
Date: Fri, 20 Sep 2024 11:48:45 +0300
Subject: [PATCH] fuzz: Fix memory leak inside fuzz-main
Found by ALT Linux Team.
Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
---
fuzzing/fuzz-main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fuzzing/fuzz-main.c b/fuzzing/fuzz-main.c
index 1de031c..90c9f64 100644
--- a/fuzzing/fuzz-main.c
+++ b/fuzzing/fuzz-main.c
@@ -25,6 +25,7 @@ int main(int argc, char **argv)
g_print("%s...\n", name);
for (j = 0; j < MIN_NUMBER_OF_RUNS; j++) {
if (LLVMFuzzerTestOneInput((void *)buf, size) == EXIT_TEST_SKIP) {
+ g_free(buf);
return EXIT_TEST_SKIP;
}
}
--
2.42.2