diff --git a/Source/Core/Common/PcapFile.cpp b/Source/Core/Common/PcapFile.cpp index 71fcdc9eee..0f248ce1b5 100644 --- a/Source/Core/Common/PcapFile.cpp +++ b/Source/Core/Common/PcapFile.cpp @@ -49,6 +49,7 @@ void PCAP::AddHeader(u32 link_type) m_fp->WriteBytes(&hdr, sizeof(hdr)); } +// Not thread-safe, concurrency between multiple calls to IOFile::WriteBytes. void PCAP::AddPacket(const u8* bytes, size_t size) { std::chrono::system_clock::time_point now(std::chrono::system_clock::now()); diff --git a/Source/Core/Core/NetworkCaptureLogger.cpp b/Source/Core/Core/NetworkCaptureLogger.cpp index 0b8e2bf5d8..d7da8e2469 100644 --- a/Source/Core/Core/NetworkCaptureLogger.cpp +++ b/Source/Core/Core/NetworkCaptureLogger.cpp @@ -123,6 +123,9 @@ void PCAPSSLCaptureLogger::LogBBA(const void* data, std::size_t length) { if (!Config::Get(Config::MAIN_NETWORK_DUMP_BBA)) return; + + // Concurrency between CEXIETHERNET's RecvHandlePacket and SendFromDirectFIFO + const std::lock_guard lock(m_io_mutex); m_file->AddPacket(static_cast(data), length); } diff --git a/Source/Core/Core/NetworkCaptureLogger.h b/Source/Core/Core/NetworkCaptureLogger.h index 3e45446ac1..89dd24030b 100644 --- a/Source/Core/Core/NetworkCaptureLogger.h +++ b/Source/Core/Core/NetworkCaptureLogger.h @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -111,6 +112,7 @@ private: const sockaddr_in& to); std::unique_ptr m_file; + std::mutex m_io_mutex; std::map m_read_sequence_number; std::map m_write_sequence_number; };