Commit a77f8184 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf expr: Use zfree() to reduce chances of use after free



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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cdf13c09
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -86,8 +86,8 @@ void ids__free(struct hashmap *ids)
		return;

	hashmap__for_each_entry(ids, cur, bkt) {
		free((void *)cur->pkey);
		free((void *)cur->pvalue);
		zfree(&cur->pkey);
		zfree(&cur->pvalue);
	}

	hashmap__free(ids);
@@ -311,8 +311,8 @@ void expr__ctx_clear(struct expr_parse_ctx *ctx)
	size_t bkt;

	hashmap__for_each_entry(ctx->ids, cur, bkt) {
		free((void *)cur->pkey);
		free(cur->pvalue);
		zfree(&cur->pkey);
		zfree(&cur->pvalue);
	}
	hashmap__clear(ctx->ids);
}
@@ -325,10 +325,10 @@ void expr__ctx_free(struct expr_parse_ctx *ctx)
	if (!ctx)
		return;

	free(ctx->sctx.user_requested_cpu_list);
	zfree(&ctx->sctx.user_requested_cpu_list);
	hashmap__for_each_entry(ctx->ids, cur, bkt) {
		free((void *)cur->pkey);
		free(cur->pvalue);
		zfree(&cur->pkey);
		zfree(&cur->pvalue);
	}
	hashmap__free(ctx->ids);
	free(ctx);