From 78f4e566bc735f101539f4b4dde0c881d2ece6c9 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 30 Jan 2006 10:45:49 +0000 Subject: [PATCH] fix a memleak Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2456 --- src/debug/debug_gui.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/debug/debug_gui.cpp b/src/debug/debug_gui.cpp index 95c42d7c..1ae6da60 100644 --- a/src/debug/debug_gui.cpp +++ b/src/debug/debug_gui.cpp @@ -16,9 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +/* $Id: debug_gui.cpp,v 1.26 2006-01-30 10:45:49 qbix79 Exp $ */ #include "dosbox.h" + #if C_DEBUG #include "setup.h" #include @@ -36,11 +37,16 @@ struct _LogGroup { char * front; bool enabled; }; +#include +#include +using namespace std; + +#define MAX_LOG_BUFFER 500 +static list logBuff; +static list::iterator logBuffPos = logBuff.end(); static _LogGroup loggrp[LOG_MAX]={{"",true},{0,false}}; static FILE* debuglog; -static std::list logBuff; -static std::list::iterator logBuffPos = logBuff.end(); extern int old_cursor_state; @@ -60,19 +66,15 @@ void DEBUG_ShowMsg(char * format,...) { if(debuglog) fprintf(debuglog,"%s",buf); - char* newLine = new char[strlen(buf) + 1]; - strcpy(newLine, buf); if (logBuffPos!=logBuff.end()) { logBuffPos=logBuff.end(); DEBUG_RefreshPage(0); mvwprintw(dbg.win_out,dbg.win_out->_maxy-1, 0, ""); } - logBuff.push_back(newLine); - if (logBuff.size()>500) { - char * firstline = logBuff.front(); - delete firstline; + logBuff.push_back(buf); + if (logBuff.size() > MAX_LOG_BUFFER) logBuff.pop_front(); - } + logBuffPos = logBuff.end(); wprintw(dbg.win_out,"%s",buf); wrefresh(dbg.win_out); @@ -82,14 +84,14 @@ void DEBUG_RefreshPage(char scroll) { if (scroll==-1 && logBuffPos!=logBuff.begin()) logBuffPos--; else if (scroll==1 && logBuffPos!=logBuff.end()) logBuffPos++; - std::list::iterator i = logBuffPos; + list::iterator i = logBuffPos; int rem_lines = dbg.win_out->_maxy; wclear(dbg.win_out); while (rem_lines > 0 && i!=logBuff.begin()) { - rem_lines -= (int) (strlen(*--i) / dbg.win_out->_maxx) + 1; - mvwprintw(dbg.win_out,rem_lines-1, 0, *i); + rem_lines -= (int) ((*--i).size() / dbg.win_out->_maxx) + 1; + mvwprintw(dbg.win_out,rem_lines-1, 0, (*i).c_str()); } wrefresh(dbg.win_out); }