fix gradual "leaking" of memory, as all info output is stored in staticlog even after the static buffer was full

This commit is contained in:
Glenn Maynard
2004-07-13 21:02:28 +00:00
parent 1c5e411bf9
commit 7c34878efc
+15 -11
View File
@@ -282,24 +282,28 @@ void RageLog::Flush()
#endif #endif
static char staticlog[1024*32]=""; static char staticlog[1024*32]="";
static CString staticlog_buf; static unsigned staticlog_size = 0;
void RageLog::AddToInfo( const CString &str ) void RageLog::AddToInfo( const CString &str )
{ {
int old_len = staticlog_buf.size(); static bool limit_reached = false;
staticlog_buf += str + NEWLINE; if( limit_reached )
return;
if( staticlog_buf.size() >= sizeof(staticlog) ) unsigned len = str.size() + strlen(NEWLINE);
if( staticlog_size + len > sizeof(staticlog) )
{ {
CString txt( NEWLINE "Staticlog limit reached" NEWLINE ); const CString txt( NEWLINE "Staticlog limit reached" NEWLINE );
unsigned size_wanted = sizeof(staticlog) - txt.size() - 1; const unsigned pos = min( staticlog_size, sizeof(staticlog) - txt.size() );
if( size_wanted < staticlog_buf.size() ) memcpy( staticlog+pos, txt.data(), txt.size() );
staticlog_buf.erase( size_wanted, CString::npos ); limit_reached = true;
staticlog_buf += txt; return;
old_len = 0;
} }
strcpy(staticlog+old_len, (const char *)(staticlog_buf) + old_len); memcpy( staticlog+staticlog_size, str.data(), str.size() );
staticlog_size += str.size();
memcpy( staticlog+staticlog_size, NEWLINE, strlen(NEWLINE) );
staticlog_size += strlen(NEWLINE);
} }
const char *RageLog::GetInfo() const char *RageLog::GetInfo()