summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJekyll Wu <adaptee@gmail.com>2011-08-20 10:55:11 (GMT)
committerKurt Hindenburg <kurt.hindenburg@gmail.com>2011-08-25 12:37:58 (GMT)
commit27d65589b4c6a71a08d2d4f674177e96738d56a7 (patch)
tree66a4f7a47ec129388137fcbb7191d2eb4b84c00b
parentb13b252e6f72916030ba10ad7c1dde5c516ffd09 (diff)
Fix a hidden bug which makes argument list grow longer for ever.
The old code updates the argument list when it is asked to refresh process info, but it calls ProcessInfo::addArgument() without ever clearing existing arguements first. This means the argument list will grow longer and longer for ever. For a long-running shell session in which user has executed thousands of commands, that will waste quite amount of memory, not to metion the logic error itself. The reaseon why this bug keeps hidden is that the %c and %C formatter have never been revealed to users, which are not implemented yet. (cherry picked from commit 20e927494337863ab9906281c11bd3ddb5387f2a)
-rw-r--r--src/ProcessInfo.cpp9
-rw-r--r--src/ProcessInfo.h7
2 files changed, 16 insertions, 0 deletions
diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp
index aa66a89..1813b98 100644
--- a/src/ProcessInfo.cpp
+++ b/src/ProcessInfo.cpp
@@ -338,6 +338,11 @@ void ProcessInfo::addArgument(const QString& argument)
_arguments << argument;
}
+void ProcessInfo::clearArguments()
+{
+ _arguments.clear();
+}
+
void ProcessInfo::addEnvironmentBinding(const QString& name , const QString& value)
{
_environment.insert(name,value);
@@ -384,6 +389,10 @@ UnixProcessInfo::UnixProcessInfo(int pid,bool enableEnvironmentRead)
bool UnixProcessInfo::readProcessInfo(int pid , bool enableEnvironmentRead)
{
+ // prevent _arguments from growing longer and longer each time this
+ // method is called.
+ clearArguments();
+
bool ok = readProcInfo(pid);
if (ok)
{
diff --git a/src/ProcessInfo.h b/src/ProcessInfo.h
index adaabc9..48b62ed 100644
--- a/src/ProcessInfo.h
+++ b/src/ProcessInfo.h
@@ -265,6 +265,13 @@ protected:
* by arguments()
*/
void addArgument(const QString& argument);
+
+ /**
+ * clear the commandline arguments for the process, as returned
+ * by arguments()
+ */
+ void clearArguments();
+
/**
* Adds an environment binding for the process, as returned by
* environment()