From 940c1f614fa380a9153c3b81d0614201b27957c2 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 19 Apr 2002 06:51:08 +0000 Subject: [PATCH] temprary fix for the memleaks in ::load() and ::set* when using ostrstreams. Need to find a better solution for strings than std::string and ostrstream, or else put up with memory leaks all over the place. --- src/Screen.cc | 46 ++++++++++++++++++++++++++++++++++------------ src/Slit.cc | 7 +++++++ src/Toolbar.cc | 7 +++++++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index 4f4718ec..44515671 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -855,6 +855,7 @@ void BScreen::setSloppyFocus(bool b) { (resource.sloppy_focus ? (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus") : "ClickToFocus")); + s.rdbuf()->freeze(0); } void BScreen::setAutoRaise(bool a) { @@ -865,6 +866,7 @@ void BScreen::setAutoRaise(bool a) { (resource.sloppy_focus ? (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus") : "ClickToFocus")); + s.rdbuf()->freeze(0); } void BScreen::setImageDither(bool d) { @@ -872,6 +874,7 @@ void BScreen::setImageDither(bool d) { ostrstream s; s << "session.screen" << getScreenNumber() << ".imageDither" << ends; config.setValue(s.str(), resource.image_dither); + s.rdbuf()->freeze(0); } void BScreen::setOpaqueMove(bool o) { @@ -879,6 +882,7 @@ void BScreen::setOpaqueMove(bool o) { ostrstream s; s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends; config.setValue(s.str(), resource.opaque_move); + s.rdbuf()->freeze(0); } void BScreen::setFullMax(bool f) { @@ -886,6 +890,7 @@ void BScreen::setFullMax(bool f) { ostrstream s; s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends; config.setValue(s.str(), resource.full_max); + s.rdbuf()->freeze(0); } void BScreen::setFocusNew(bool f) { @@ -893,6 +898,7 @@ void BScreen::setFocusNew(bool f) { ostrstream s; s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends; config.setValue(s.str(), resource.focus_new); + s.rdbuf()->freeze(0); } void BScreen::setFocusLast(bool f) { @@ -900,6 +906,7 @@ void BScreen::setFocusLast(bool f) { ostrstream s; s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends; config.setValue(s.str(), resource.focus_last); + s.rdbuf()->freeze(0); } void BScreen::setWindowZones(int z) { @@ -907,6 +914,7 @@ void BScreen::setWindowZones(int z) { ostrstream s; s << "session.screen" << getScreenNumber() << ".windowZones" << ends; config.setValue(s.str(), resource.zones); + s.rdbuf()->freeze(0); } void BScreen::setWorkspaceCount(int w) { @@ -914,6 +922,7 @@ void BScreen::setWorkspaceCount(int w) { ostrstream s; s << "session.screen" << getScreenNumber() << ".workspaces" << ends; config.setValue(s.str(), resource.workspaces); + s.rdbuf()->freeze(0); } void BScreen::setPlacementPolicy(int p) { @@ -929,6 +938,7 @@ void BScreen::setPlacementPolicy(int p) { case RowSmartPlacement: placement = "RowSmartPlacement"; break; } config.setValue(s.str(), placement); + s.rdbuf()->freeze(0); } void BScreen::setEdgeSnapThreshold(int t) { @@ -936,6 +946,7 @@ void BScreen::setEdgeSnapThreshold(int t) { ostrstream s; s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends; config.setValue(s.str(), resource.edge_snap_threshold); + s.rdbuf()->freeze(0); } void BScreen::setRowPlacementDirection(int d) { @@ -946,6 +957,7 @@ void BScreen::setRowPlacementDirection(int d) { config.setValue(s.str(), resource.row_direction == LeftRight ? "LeftToRight" : "RightToLeft"); + s.rdbuf()->freeze(0); } void BScreen::setColPlacementDirection(int d) { @@ -956,6 +968,7 @@ void BScreen::setColPlacementDirection(int d) { config.setValue(s.str(), resource.col_direction == TopBottom ? "TopToBottom" : "BottomToTop"); + s.rdbuf()->freeze(0); } void BScreen::setRootCommand(const char *cmd) { @@ -978,6 +991,7 @@ void BScreen::setStrftimeFormat(const char *f) { ostrstream s; s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends; config.setValue(s.str(), resource.strftime_format); + s.rdbuf()->freeze(0); } #else // !HAVE_STRFTIME @@ -987,6 +1001,7 @@ void BScreen::setDateFormat(int f) { s << "session.screen" << getScreenNumber() << ".dateFormat" << ends; config.setValue(s.str(), resource.date_format == B_EuropeanDate ? "European" : "American"); + s.rdbuf()->freeze(0); } void BScreen::setClock24Hour(Bool c) { @@ -994,6 +1009,7 @@ void BScreen::setClock24Hour(Bool c) { ostrstream s; s << "session.screen" << getScreenNumber() << ".clockFormat" << ends; config.setValue(s.str(), resource.clock24hour ? 24 : 12); + s.rdbuf()->freeze(0); } #endif // HAVE_STRFTIME @@ -1006,23 +1022,26 @@ void BScreen::setHideToolbar(bool b) { ostrstream s; s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends; config.setValue(s.str(), resource.hide_toolbar ? "True" : "False"); + s.rdbuf()->freeze(0); } void BScreen::saveWorkspaceNames() { - ostrstream rc, names; - - for (int i = 0; i < resource.workspaces; i++) { - Workspace *w = getWorkspace(i); - if (w != NULL) { - names << w->getName(); - if (i < resource.workspaces-1) - names << ','; - } + ostrstream rc, names; + + for (int i = 0; i < resource.workspaces; i++) { + Workspace *w = getWorkspace(i); + if (w != NULL) { + names << w->getName(); + if (i < resource.workspaces-1) + names << ','; } - names << ends; + } + names << ends; - rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends; - config.setValue(rc.str(), names.str()); + rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends; + config.setValue(rc.str(), names.str()); + rc.rdbuf()->freeze(0); + names.rdbuf()->freeze(0); } void BScreen::save() { @@ -1219,6 +1238,9 @@ void BScreen::load() { rclass << rscreen.str() << "OpaqueMove" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.opaque_move = b; + rscreen.rdbuf()->freeze(0); + rname.rdbuf()->freeze(0); + rclass.rdbuf()->freeze(0); } void BScreen::reconfigure(void) { diff --git a/src/Slit.cc b/src/Slit.cc index 2fbce2d1..38af8b93 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -220,6 +220,7 @@ void Slit::setOnTop(bool b) { ostrstream s; s << "session.screen" << screen.getScreenNumber() << ".slit.onTop" << ends; config.setValue(s.str(), m_ontop ? "True" : "False"); + s.rdbuf()->freeze(0); } void Slit::setAutoHide(bool b) { @@ -227,6 +228,7 @@ void Slit::setAutoHide(bool b) { ostrstream s; s << "session.screen" << screen.getScreenNumber() << ".slit.autoHide" << ends; config.setValue(s.str(), m_autohide ? "True" : "False"); + s.rdbuf()->freeze(0); } void Slit::setPlacement(int p) { @@ -246,6 +248,7 @@ void Slit::setPlacement(int p) { case CenterRight: default: placement = "CenterRight"; break; } config.setValue(s.str(), placement); + s.rdbuf()->freeze(0); } void Slit::setDirection(int d) { @@ -255,6 +258,7 @@ void Slit::setDirection(int d) { ends; config.setValue(s.str(), m_direction == Horizontal ? "Horizontal" : "Vertical"); + s.rdbuf()->freeze(0); } void Slit::save() { @@ -312,6 +316,9 @@ void Slit::load() { rclass << rscreen.str() << "Slit.AutoHide" << ends; if (config.getValue(rname.str(), rclass.str(), b)) m_hidden = m_autohide = b; + rscreen.rdbuf()->freeze(0); + rname.rdbuf()->freeze(0); + rclass.rdbuf()->freeze(0); } void Slit::reconfigure(void) { diff --git a/src/Toolbar.cc b/src/Toolbar.cc index d0753aab..a6da46a9 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -223,6 +223,7 @@ void Toolbar::setOnTop(bool b) { ostrstream s; s << "session.screen" << screen.getScreenNumber() << ".toolbar.onTop" << ends; config.setValue(s.str(), m_ontop ? "True" : "False"); + s.rdbuf()->freeze(0); } void Toolbar::setAutoHide(bool b) { @@ -231,6 +232,7 @@ void Toolbar::setAutoHide(bool b) { s << "session.screen" << screen.getScreenNumber() << ".toolbar.autoHide" << ends; config.setValue(s.str(), m_autohide ? "True" : "False"); + s.rdbuf()->freeze(0); } void Toolbar::setWidthPercent(int w) { @@ -239,6 +241,7 @@ void Toolbar::setWidthPercent(int w) { s << "session.screen" << screen.getScreenNumber() << ".toolbar.widthPercent" << ends; config.setValue(s.str(), m_width_percent); + s.rdbuf()->freeze(0); } void Toolbar::setPlacement(int p) { @@ -256,6 +259,7 @@ void Toolbar::setPlacement(int p) { case BottomCenter: default: placement = "BottomCenter"; break; } config.setValue(s.str(), placement); + s.rdbuf()->freeze(0); } void Toolbar::save() { @@ -306,6 +310,9 @@ void Toolbar::load() { rclass << rscreen.str() << "Toolbar.AutoHide" << ends; if (config.getValue(rname.str(), rclass.str(), b)) m_hidden = m_autohide = b; + rscreen.rdbuf()->freeze(0); + rname.rdbuf()->freeze(0); + rclass.rdbuf()->freeze(0); } void Toolbar::reconfigure() { -- 2.45.2