改进 xy_file_exist 的变量命名,修复内存泄露

This commit is contained in:
Mikachu2333
2025-10-06 01:54:13 +08:00
parent b2a844b676
commit 437729a5cf

View File

@@ -1164,13 +1164,19 @@ _xy_win_powershellv5_profile ()
static bool static bool
xy_file_exist (const char *path) xy_file_exist (const char *path)
{ {
const char *new_path = path; char *expanded_path = NULL;
const char *check_path = path;
if (xy_str_start_with (path, "~")) if (xy_str_start_with (path, "~"))
{ {
new_path = xy_2strcat (xy_os_home, path + 1); expanded_path = xy_2strcat (xy_os_home, path + 1);
check_path = expanded_path;
} }
// 0 即 F_OK // 0 即 F_OK
return (0==access (new_path, 0)) ? true : false; bool result = (0 == access (check_path, 0)) ? true : false;
if (expanded_path) free (expanded_path);
return result;
} }
/** /**