From 2814677a7e2b259669708c89ed55b55dc1c46f9c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 28 Nov 2017 21:58:07 +0100 Subject: Loop.cpp: fix more memory leaks The thread specific stringstream objects on the stack need to be deleted, not just pop()ed. Fixes ArcticaProject/nx-libs#573 (partially) --- nxcomp/src/Log.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'nxcomp') diff --git a/nxcomp/src/Log.h b/nxcomp/src/Log.h index aed929b31..3e355a951 100644 --- a/nxcomp/src/Log.h +++ b/nxcomp/src/Log.h @@ -168,7 +168,13 @@ class NXLog delete pdt->thread_name; while (!pdt->buffer.empty()) { + /* + * get the stringstream object created in new_stack_entry() + * from the stack and delete it after pop() + */ + std::stringstream* tmp = pdt->buffer.top(); (void) pdt->buffer.pop (); + delete tmp; } delete pdt; @@ -240,7 +246,12 @@ class NXLog pthread_sigmask(SIG_BLOCK, &tmp_signal_mask, &orig_signal_mask); if (!pdt->buffer.empty ()) { - const std::string str = pdt->buffer.top()->str(); + /* + * get the stringstream object created in new_stack_entry() + * from the stack and delete it after pop() + */ + std::stringstream *tmp = pdt->buffer.top(); + const std::string str = tmp->str(); if (!str.empty()) { @@ -251,6 +262,9 @@ class NXLog /* Remove from stack. */ pdt->buffer.pop(); + + /* free memory */ + delete tmp; } /* Restore old signal mask. */ -- cgit v1.2.3