From d4d4163cb3d1f827efd9ea2df9dd9838d12f5d72 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 25 Feb 2023 16:40:38 +0100 Subject: [PATCH] Fix an eventual memory leak --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index e2aba716f..b47b8b118 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -801,8 +801,6 @@ bool FileManager::reloadBuffer(BufferID id) Document doc = buf->getDocument(); Utf8_16_Read UnicodeConvertor; - char* data = new char[blockSize + 8]; // +8 for incomplete multibyte char - LoadedFileFormat loadedFileFormat; loadedFileFormat._encoding = buf->getEncoding(); loadedFileFormat._eolFormat = EolType::unknown; @@ -811,7 +809,6 @@ bool FileManager::reloadBuffer(BufferID id) buf->setLoadedDirty(false); // Since the buffer will be reloaded from the disk, and it will be clean (not dirty), we can set _isLoadedDirty false safetly. // Set _isLoadedDirty false before calling "_pscratchTilla->execute(SCI_CLEARALL);" in loadFileData() to avoid setDirty in SCN_SAVEPOINTREACHED / SCN_SAVEPOINTLEFT - //Get file size FILE* fp = _wfopen(buf->getFullPathName(), TEXT("rb")); if (!fp) @@ -819,6 +816,8 @@ bool FileManager::reloadBuffer(BufferID id) _fseeki64(fp, 0, SEEK_END); int64_t fileSize = _ftelli64(fp); fclose(fp); + + char* data = new char[blockSize + 8]; // +8 for incomplete multibyte char buf->_canNotify = false; //disable notify during file load, we don't want dirty status to be triggered bool res = loadFileData(doc, fileSize, buf->getFullPathName(), data, &UnicodeConvertor, loadedFileFormat);