From 7c34878efc7cdec97c85cb2c612b3b283aaf1f34 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 13 Jul 2004 21:02:28 +0000 Subject: [PATCH] fix gradual "leaking" of memory, as all info output is stored in staticlog even after the static buffer was full --- stepmania/src/RageLog.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/stepmania/src/RageLog.cpp b/stepmania/src/RageLog.cpp index 408d404b34..c45237fc2a 100644 --- a/stepmania/src/RageLog.cpp +++ b/stepmania/src/RageLog.cpp @@ -282,24 +282,28 @@ void RageLog::Flush() #endif static char staticlog[1024*32]=""; -static CString staticlog_buf; +static unsigned staticlog_size = 0; void RageLog::AddToInfo( const CString &str ) { - int old_len = staticlog_buf.size(); - staticlog_buf += str + NEWLINE; - - if( staticlog_buf.size() >= sizeof(staticlog) ) + static bool limit_reached = false; + if( limit_reached ) + return; + + unsigned len = str.size() + strlen(NEWLINE); + if( staticlog_size + len > sizeof(staticlog) ) { - CString txt( NEWLINE "Staticlog limit reached" NEWLINE ); - - unsigned size_wanted = sizeof(staticlog) - txt.size() - 1; - if( size_wanted < staticlog_buf.size() ) - staticlog_buf.erase( size_wanted, CString::npos ); - staticlog_buf += txt; - old_len = 0; + const CString txt( NEWLINE "Staticlog limit reached" NEWLINE ); + + const unsigned pos = min( staticlog_size, sizeof(staticlog) - txt.size() ); + memcpy( staticlog+pos, txt.data(), txt.size() ); + limit_reached = true; + return; } - 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()