From 1274f2ba07abc19646b59c03438eb98b43ac1ebc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 18 Mar 2012 00:27:47 -0400 Subject: [PATCH] Code Cleanup - Addressed valgrind complaints by freeing allocations for commands and columns. This leaves one complaint about getpwuid, which is either an optional free, or not valid, depending on OS. (Thanks to Bryce Harrington). --- ChangeLog | 1 + src/Context.cpp | 11 +++++++++++ src/ViewTask.cpp | 10 ++++++++++ src/ViewTask.h | 2 +- src/ViewText.cpp | 10 ++++++++++ src/ViewText.h | 2 +- 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 444931682..395a5b73b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ ------ current release --------------------------- 2.0.1 () + + Addressed valgrind complaints (thanks to Bryce Harrington). ------ old releases ------------------------------ diff --git a/src/Context.cpp b/src/Context.cpp index 09b8b0b6d..1ffa17566 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -66,6 +66,13 @@ Context::Context () //////////////////////////////////////////////////////////////////////////////// Context::~Context () { + std::map::iterator com; + for (com = commands.begin (); com != commands.end (); ++com) + delete com->second; + + std::map::iterator col; + for (col = columns.begin (); col != columns.end (); ++col) + delete col->second; } //////////////////////////////////////////////////////////////////////////////// @@ -564,6 +571,10 @@ const std::vector Context::getCommands () const //////////////////////////////////////////////////////////////////////////////// void Context::assumeLocations () { + // Note that this pointer is deliberately not free()'d, even though valgrind + // complains about it. It is either not necessary, or forbidden, depending + // on OS. + // Set up default locations. struct passwd* pw = getpwuid (getuid ()); if (!pw) diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index d2eaf3a13..c65255471 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -56,6 +56,16 @@ ViewTask::ViewTask () { } +//////////////////////////////////////////////////////////////////////////////// +ViewTask::~ViewTask () +{ + std::vector ::iterator i; + for (i = _columns.begin (); i != _columns.end (); ++i) + delete *i; + + _columns.clear (); +} + //////////////////////////////////////////////////////////////////////////////// // |<---------- terminal width ---------->| // diff --git a/src/ViewTask.h b/src/ViewTask.h index 3b6dd3c50..50a09231d 100644 --- a/src/ViewTask.h +++ b/src/ViewTask.h @@ -39,7 +39,7 @@ class ViewTask { public: ViewTask (); - ~ViewTask () {} + ~ViewTask (); // View specifications. void add (Column* column) { _columns.push_back (column); } diff --git a/src/ViewText.cpp b/src/ViewText.cpp index 88fcf16d6..462d27c17 100644 --- a/src/ViewText.cpp +++ b/src/ViewText.cpp @@ -55,6 +55,16 @@ ViewText::ViewText () { } +//////////////////////////////////////////////////////////////////////////////// +ViewText::~ViewText () +{ + std::vector ::iterator i; + for (i = _columns.begin (); i != _columns.end (); ++i) + delete *i; + + _columns.clear (); +} + //////////////////////////////////////////////////////////////////////////////// int ViewText::addRow () { diff --git a/src/ViewText.h b/src/ViewText.h index fe43dedb3..928b84bbb 100644 --- a/src/ViewText.h +++ b/src/ViewText.h @@ -39,7 +39,7 @@ class ViewText { public: ViewText (); - ~ViewText () {} + ~ViewText (); // View specifications. void add (Column* col) { _columns.push_back (col); }