com php-src: Avoid early allocation: win32/readdir.c

From: Date: Fri, 13 Jul 2018 05:35:33 +0000
Subject: com php-src: Avoid early allocation: win32/readdir.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-102543@lists.php.net to get a copy of this message
Commit: 1bcc2fcb4e7f549a07f3ee8c85604e26ed3ac911 Author: Anatol Belski <ab@php.net> Fri, 13 Jul 2018 07:35:33 +0200 Parents: 54f920d661f385debc4e2024e21a449128d611e7 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1bcc2fcb4e7f549a07f3ee8c85604e26ed3ac911 Log: Avoid early allocation Changed paths: M win32/readdir.c Diff: diff --git a/win32/readdir.c b/win32/readdir.c index f3d33e6..0d46f14 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) {

« previous php.cvs (#102543) next »