1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Avoid early allocation

This commit is contained in:
Anatol Belski
2018-07-13 07:35:33 +02:00
parent 54f920d661
commit 1bcc2fcb4e

View File

@@ -37,14 +37,8 @@ DIR *opendir(const char *dir)
return NULL;
}
dp = (DIR *) calloc(1, sizeof(DIR) + (_MAX_FNAME*5+1)*sizeof(char));
if (dp == NULL) {
return NULL;
}
resolvedw = php_win32_ioutil_conv_any_to_w(resolved_path_buff, PHP_WIN32_CP_IGNORE_LEN, &resolvedw_len);
if (!resolvedw) {
free(dp);
return NULL;
}
@@ -56,7 +50,6 @@ DIR *opendir(const char *dir)
}
filespecw = (wchar_t *)malloc((filespecw_len + 1)*sizeof(wchar_t));
if (filespecw == NULL) {
free(dp);
free(resolvedw);
return NULL;
}
@@ -73,6 +66,12 @@ DIR *opendir(const char *dir)
filespecw[index] = L'\0';
wcscat(filespecw, L"\\*");
dp = (DIR *) calloc(1, sizeof(DIR) + (_MAX_FNAME*5+1)*sizeof(char));
if (dp == NULL) {
free(resolvedw);
return NULL;
}
if ((handle = FindFirstFileExW(filespecw, FindExInfoBasic, &(dp->fileinfo), FindExSearchNameMatch, NULL, FIND_FIRST_EX_LARGE_FETCH)) == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
if (err == ERROR_NO_MORE_FILES || err == ERROR_FILE_NOT_FOUND) {