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.
This commit is contained in:
Xavier Del Campo Romero 2023-07-07 22:01:13 +02:00
parent 74b7f7a902
commit 960a35a02f
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
1 changed files with 1 additions and 1 deletions

2
main.c
View File

@ -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;
}