LibC: Fix potential double free in ttyname_r_for_directory

If we break out of the loop before we attempt to allocate again,
then we double free the memory pointed to by `name_path`.

Found by Static Analysis: Sonar Cloud
This commit is contained in:
Brian Gianforcaro 2022-03-27 15:48:16 -07:00 committed by Brian Gianforcaro
parent 4674577d80
commit ecc0459f76
Notes: sideshowbarker 2024-07-18 00:34:07 +09:00

View file

@ -438,6 +438,7 @@ static int ttyname_r_for_directory(const char* directory_name, dev_t device_mode
struct stat st;
if (lstat(name_path, &st) < 0) {
free(name_path);
name_path = nullptr;
continue;
}