diff options
author | Anatol Belski <ab@php.net> | 2018-07-13 07:35:33 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2018-07-13 07:35:33 +0200 |
commit | 1bcc2fcb4e7f549a07f3ee8c85604e26ed3ac911 (patch) | |
tree | a6580aa0a47628e557892ce5e671d35be4ac02ae | |
parent | 54f920d661f385debc4e2024e21a449128d611e7 (diff) | |
download | php-git-1bcc2fcb4e7f549a07f3ee8c85604e26ed3ac911.tar.gz |
Avoid early allocation
-rw-r--r-- | win32/readdir.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/win32/readdir.c b/win32/readdir.c index f3d33e61d7..0d46f14a77 100644 --- a/win32/readdir.c +++ b/win32/readdir.c @@ -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) { |