OSDN Git Service

perf parse-events: 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:07:06 +0000 (10:07 -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.

Also remove one NULL test before free(), as it accepts a NULL arg and we
get one line shaved not doing it explicitely.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c

index f341995..d71019d 100644 (file)
@@ -2020,7 +2020,7 @@ int perf_pmu__test_parse_init(void)
 
 err_free:
        for (j = 0, tmp = list; j < i; j++, tmp++)
-               free(tmp->symbol);
+               zfree(&tmp->symbol);
        free(list);
        return -ENOMEM;
 }