perf x86 iostat: 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 12:59:19 +0000 (09:59 -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/arch/x86/util/iostat.c

index 7eb0a7b..df7b5df 100644 (file)
@@ -10,6 +10,7 @@
 #include <api/fs/fs.h>
 #include <linux/kernel.h>
 #include <linux/err.h>
+#include <linux/zalloc.h>
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
@@ -100,8 +101,8 @@ static void iio_root_ports_list_free(struct iio_root_ports_list *list)
 
        if (list) {
                for (idx = 0; idx < list->nr_entries; idx++)
-                       free(list->rps[idx]);
-               free(list->rps);
+                       zfree(&list->rps[idx]);
+               zfree(&list->rps);
                free(list);
        }
 }
@@ -390,7 +391,7 @@ void iostat_release(struct evlist *evlist)
        evlist__for_each_entry(evlist, evsel) {
                if (rp != evsel->priv) {
                        rp = evsel->priv;
-                       free(evsel->priv);
+                       zfree(&evsel->priv);
                }
        }
 }