diff options
author | mread <qt-info@nokia.com> | 2010-12-10 08:13:13 (GMT) |
---|---|---|
committer | mread <qt-info@nokia.com> | 2010-12-10 12:52:42 (GMT) |
commit | 92f2ec30b86b7bf33fd632c8eb71318c9008a7ba (patch) | |
tree | 8fcc3d123ccb60983a12194d4309dd9d77dcbb7d /src/s60main | |
parent | 85a7b344571b5bb4b06bdef88a11a4e01f97d6ad (diff) | |
download | Qt-92f2ec30b86b7bf33fd632c8eb71318c9008a7ba.zip Qt-92f2ec30b86b7bf33fd632c8eb71318c9008a7ba.tar.gz Qt-92f2ec30b86b7bf33fd632c8eb71318c9008a7ba.tar.bz2 |
Improving memory leak analysis for argv, envp
QtMainWrapper() gets the argv and envp arrays from __crt0(). There have
been memory leaks reported from QtMainWrapper() because the contents of
argv and envp are not deleted when the function returns. There has been
some attempt to delete the memory with "delete []" on the top level
arrays, but this will not delete any memory allocated for the strings
themselves.
The big problem is that there is no function which will free argv and
envp properly. QtMainWrapper() can only guess at what is the best way
to free the arrays. If QtMainWrapper() reverses the implementation of
__crt0(), it is then tied to the current implementation of that
function in an unrelated component.
Instead we want these arrays to not be viewed as memory leaks when the
app exits. QrMainWrapper() is only ever called as a top level function
before main(), and the memory will be released automatically when the
app exists shortly after the funciton returns. So in practice there is
no meaningful leak from not freeing these arrays.
The memory leak analysis tools should be able to spot heap ownership
rooted in static data, and not treat that as a leak. In this case it
is valid to put the argv and envp pointers in static data. Doing this
should stop leaks being reported from these arrays.
Task-number: QTBUG-15687
Reviewed-by: axis
Diffstat (limited to 'src/s60main')
-rw-r--r-- | src/s60main/qts60main_mcrt0.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/s60main/qts60main_mcrt0.cpp b/src/s60main/qts60main_mcrt0.cpp index 0f0723e..ddab771 100644 --- a/src/s60main/qts60main_mcrt0.cpp +++ b/src/s60main/qts60main_mcrt0.cpp @@ -78,14 +78,14 @@ extern "C" IMPORT_C void exit(int ret); GLDEF_C TInt QtMainWrapper() { int argc = 0; - char **argv = 0; - char **envp = 0; + // these variables are declared static in the expectation that this function is not reentrant + // and so that memory analysis tools can trace any memory allocated in __crt0() to global memory ownership. + static char **argv = 0; + static char **envp = 0; // get args & environment __crt0(argc, argv, envp); //Call user(application)'s main TRAPD(ret, QT_TRYCATCH_LEAVING(ret = CALLMAIN(argc, argv, envp);)); - delete[] argv; - delete[] envp; return ret; } |