Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 37d0870

Browse files
authored
Merge pull request #635 from adobe/nethip/FixFileOpenCrash
Fix for 13839: Crash on opening file with error "sharing violation".
2 parents ce6fc09 + b88b669 commit 37d0870

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

appshell/appshell_extensions_win.cpp

+6-22
Original file line numberDiff line numberDiff line change
@@ -913,26 +913,6 @@ std::wstring StringToWString(const std::string& str)
913913
return converterX.from_bytes(str);
914914
}
915915

916-
class ReadFileHandle {
917-
HANDLE hFile;
918-
public:
919-
ReadFileHandle(const std::wstring& filename) {
920-
hFile = CreateFile(filename.c_str(), GENERIC_READ,
921-
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
922-
if (INVALID_HANDLE_VALUE == hFile)
923-
throw "Could not initialize read handle";
924-
}
925-
~ReadFileHandle() {
926-
if (hFile)
927-
CloseHandle(hFile);
928-
}
929-
operator HANDLE() {
930-
return hFile;
931-
}
932-
};
933-
934-
935-
936916
int32 ReadFile(ExtensionString filename, ExtensionString& encoding, std::string& contents, bool& preserveBOM)
937917
{
938918
if (encoding == L"utf8") {
@@ -946,10 +926,13 @@ int32 ReadFile(ExtensionString filename, ExtensionString& encoding, std::string&
946926
if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
947927
return ERR_CANT_READ;
948928

949-
ReadFileHandle readFileHandle(filename);
950-
HANDLE hFile = readFileHandle;
929+
HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ,
930+
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
951931
int32 error = NO_ERROR;
952932

933+
if (INVALID_HANDLE_VALUE == hFile)
934+
return ConvertWinErrorCode(GetLastError());
935+
953936
DWORD dwFileSize = GetFileSize(hFile, NULL);
954937

955938
if (dwFileSize == 0) {
@@ -1027,6 +1010,7 @@ int32 ReadFile(ExtensionString filename, ExtensionString& encoding, std::string&
10271010
}
10281011
}
10291012
}
1013+
CloseHandle(hFile);
10301014
return error;
10311015
}
10321016

0 commit comments

Comments
 (0)