OSDN Git Service

perf bench inject-buildid: 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:01 +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/bench/inject-buildid.c

index 4561bda..4933174 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/time64.h>
 #include <linux/list.h>
 #include <linux/err.h>
+#include <linux/zalloc.h>
 #include <internal/lib.h>
 #include <subcmd/parse-options.h>
 
@@ -122,7 +123,7 @@ static void release_dso(void)
        for (i = 0; i < nr_dsos; i++) {
                struct bench_dso *dso = &dsos[i];
 
-               free(dso->name);
+               zfree(&dso->name);
        }
        free(dsos);
 }