Skip to content
Snippets Groups Projects
Commit 56024357 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6392: fix memory leak in history

parent 3518de4a
No related branches found
No related tags found
No related merge requests found
...@@ -35,27 +35,26 @@ ...@@ -35,27 +35,26 @@
#include <cc++/file.h> #include <cc++/file.h>
#include <time.h> #include <time.h>
namespace {
static void free_history(HistoryItemMap &history_items)
{
HistoryItemMap::iterator iter;
for (iter = history_items.begin(); iter != history_items.end(); ++iter)
delete *iter;
history_items.clear ();
}
} // end anonymous namespace
HistoryManager::HistoryManager () HistoryManager::HistoryManager ()
: _history_loaded (false), : _history_loaded (false),
_history_path ("") _history_path ("")
{ {
} }
HistoryManager::~HistoryManager () HistoryManager::~HistoryManager ()
{ {
HistoryItemMap::iterator iter = _history_items.begin(); free_history(_history_items);
HistoryItem * item;
while (iter != _history_items.end()) {
item = *iter;
delete item;
iter++;
}
// Clear the history map
_history_items.clear ();
} }
int HistoryManager::load_history (int limit, std::string path) int HistoryManager::load_history (int limit, std::string path)
...@@ -277,15 +276,14 @@ int HistoryManager::set_serialized_history (std::vector<std::string> history, in ...@@ -277,15 +276,14 @@ int HistoryManager::set_serialized_history (std::vector<std::string> history, in
_debug("HistoryManager: Set serialized history"); _debug("HistoryManager: Set serialized history");
// Clear the existing history // Clear the existing history
_history_items.clear (); free_history(_history_items);
// We want to save only the items recent enough (ie compared to CONFIG_HISTORY_LIMIT) // We want to save only the items recent enough (ie compared to CONFIG_HISTORY_LIMIT)
// Get the current timestamp // Get the current timestamp
(void) time (&current_timestamp); (void) time (&current_timestamp);
history_limit = get_unix_timestamp_equivalent (limit); history_limit = get_unix_timestamp_equivalent (limit);
iter = history.begin ();
while (iter != history.end ()) { for (iter = history.begin () ; iter != history.end () ; iter ++) {
new_item = new HistoryItem(*iter); new_item = new HistoryItem(*iter);
if(new_item == NULL) { if(new_item == NULL) {
_error("HistoryManager: Error: Could not create history item"); _error("HistoryManager: Error: Could not create history item");
...@@ -294,12 +292,9 @@ int HistoryManager::set_serialized_history (std::vector<std::string> history, in ...@@ -294,12 +292,9 @@ int HistoryManager::set_serialized_history (std::vector<std::string> history, in
if (item_timestamp >= ( (int) current_timestamp - history_limit)) { if (item_timestamp >= ( (int) current_timestamp - history_limit)) {
add_new_history_entry (new_item); add_new_history_entry (new_item);
items_added ++; items_added ++;
} } else {
else {
delete new_item; delete new_item;
} }
iter ++;
} }
return items_added; return items_added;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment