This should fix the use after free rare issue: C++ destroys class members in reverse declaration order. mProcess was declared before mHandlers. So during destruction, mHandlers was freed first, then mProcess destructor ran and joined the async read threads but by then the threads were already accessing freed memory.

This commit is contained in:
Martín Lucas Golini
2026-06-11 20:47:27 -03:00
parent 10588e3eb4
commit b91b922ac8
2 changed files with 1 additions and 5 deletions

View File

@@ -2119,7 +2119,6 @@ void LSPClientServer::processRequest( const json& msg ) {
}
void LSPClientServer::readStdOut( const char* bytes, size_t n ) {
BoolScopedOp op( mReadingStdOut );
if ( mEnded )
return;
mReceive.append( bytes, n );
@@ -2261,7 +2260,6 @@ void LSPClientServer::notifyServerError() {
}
void LSPClientServer::readStdErr( const char* bytes, size_t n ) {
BoolScopedOp op( mReadingStdErr );
if ( mEnded )
return;

View File

@@ -274,7 +274,6 @@ class LSPClientServer {
String::HashType mId;
LSPDefinition mLSP;
std::string mRootPath;
Process mProcess;
TcpSocket* mSocket{ nullptr };
std::vector<TextDocument*> mDocs;
std::unordered_map<TextDocument*, std::unique_ptr<LSPDocumentClient>> mClients;
@@ -289,8 +288,6 @@ class LSPClientServer {
bool mNotifiedServerError{ false };
bool mShuttingDown{ false };
bool mIsProcessingQueue{ false };
bool mReadingStdOut{ false };
bool mReadingStdErr{ false };
std::atomic<int> mWritingStdIn{ 0 };
struct QueueMessage {
json msg;
@@ -315,6 +312,7 @@ class LSPClientServer {
std::mutex mShutdownMutex;
std::condition_variable mShutdownCond;
std::atomic<int> mLastMsgId{ 0 };
Process mProcess;
void readStdOut( const char* bytes, size_t n );