OSDN Git Service

perf tests api-io: Use zfree() to reduce chances of use after free
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 12 Apr 2023 12:50:08 +0000 (09:50 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 12 Apr 2023 13:14:58 +0000 (10:14 -0300)
Do defensive programming by using zfree() to initialize freed pointers
to NULL, so that eventual use after free result in a NULL pointer deref
instead of more subtle behaviour.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/api-io.c

index 6aea84c..0ba3d5c 100644 (file)
@@ -12,6 +12,7 @@
 #include "tests.h"
 #include <api/io.h>
 #include <linux/kernel.h>
+#include <linux/zalloc.h>
 
 #define TEMPL "/tmp/perf-test-XXXXXX"
 
@@ -79,7 +80,7 @@ static int setup_test(char path[PATH_MAX], const char *contents,
 
 static void cleanup_test(char path[PATH_MAX], struct io *io)
 {
-       free(io->buf);
+       zfree(&io->buf);
        close(io->fd);
        unlink(path);
 }