From 9439291e2d3743b3b81e347c6ff2a827afd69575 Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 31 Mar 2009 09:07:02 +0000 Subject: [PATCH] DCCSock: Make sure we don't cache too much data in memory This now only reads new data from disk if there is less than 1 MiB left to be sent, which is still a lot. Before this there was no limit and the other end of the socket could try to make us run out of memory. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1463 726aef4b-f618-498e-8847-2d620e286838 --- DCCSock.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DCCSock.cpp b/DCCSock.cpp index a40a4609..a1b4583b 100644 --- a/DCCSock.cpp +++ b/DCCSock.cpp @@ -111,6 +111,14 @@ void CDCCSock::SendPacket() { return; } + if (GetInternalWriteBuffer().size() > 1024 * 1024) { + // There is still enough data to be written, don't add more + // stuff to that buffer. + DEBUG("SendPacket(): Skipping send, buffer still full enough [" << GetInternalWriteBuffer().size() << "][" + << m_sRemoteNick << "][" << m_sFileName << "]"); + return; + } + char szBuf[4096]; int iLen = m_pFile->Read(szBuf, 4096);