dirent** list was uninitialized, so scandir failure (returning -1) left it with indeterminate value. The unconditional free(list) at the end was then UB — typically heap corruption or crash.
dirent** list was uninitialized, so scandir failure (returning -1) left it with indeterminate value. The unconditional free(list) at the end was then UB — typically heap corruption or crash.