From 960a35a02fa8c98036e73be8fee9ea3f1c0888e9 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Fri, 7 Jul 2023 22:01:13 +0200 Subject: main.c: Fix use-after-free on failed search_fn When search_fn fails, it must free `r` before `results`, as the former is assigned based on the latter - otherwise, it would lead to undefined behaviour. So far, only memory allocation errors would make search_fn to fail. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index ef1dde3..048b1ba 100644 --- a/main.c +++ b/main.c @@ -610,8 +610,8 @@ static int search_fn(const char *const fpath, const struct stat *const sb, return 0; failure: - free(results); search_result_free(r); + free(results); return -1; } -- cgit v1.2.3