fix some leaks found by valgrind. r=trivial

This commit is contained in:
Chris Jones 2009-12-04 18:15:44 -06:00
parent 5035b52067
commit ba122c592e
5 changed files with 84 additions and 7 deletions

View File

@ -4,6 +4,7 @@
#include "IPDLUnitTests.h"
#include <stdlib.h>
#include <string.h>
#include "base/command_line.h"
@ -111,7 +112,27 @@ IPDLUnitTest()
// parent process only
namespace {
void* gParentActor = NULL;
IPDLUnitTestSubprocess* gSubprocess;
void
DeleteParentGlobals()
{
delete gSubprocess;
if (!gParentActor)
return;
switch (IPDLUnitTest()) {
//-----------------------------------------------------------------------------
//===== TEMPLATED =====
${PARENT_DELETE_CASES}
//-----------------------------------------------------------------------------
default: mozilla::_ipdltest::fail("???");
}
}
}
@ -134,15 +155,18 @@ IPDLUnitTestMain(void* aData)
std::vector<std::string> testCaseArgs;
testCaseArgs.push_back(testString);
IPDLUnitTestSubprocess* subprocess = new IPDLUnitTestSubprocess();
if (!subprocess->SyncLaunch(testCaseArgs))
gSubprocess = new IPDLUnitTestSubprocess();
if (!gSubprocess->SyncLaunch(testCaseArgs))
fail("problem launching subprocess");
IPC::Channel* transport = subprocess->GetChannel();
IPC::Channel* transport = gSubprocess->GetChannel();
if (!transport)
fail("no transport");
base::ProcessHandle child = subprocess->GetChildProcessHandle();
base::ProcessHandle child = gSubprocess->GetChildProcessHandle();
if (atexit(DeleteParentGlobals))
fail("can't install atexit() handler");
switch (test) {
//-----------------------------------------------------------------------------
@ -164,7 +188,24 @@ ${PARENT_MAIN_CASES}
// child process only
namespace {
void* gChildActor = NULL;
void
DeleteChildActor()
{
if (!gChildActor)
return;
switch (IPDLUnitTest()) {
//-----------------------------------------------------------------------------
//===== TEMPLATED =====
${CHILD_DELETE_CASES}
//-----------------------------------------------------------------------------
default: mozilla::_ipdltest::fail("???");
}
}
}
@ -176,6 +217,9 @@ IPDLUnitTestChildInit(IPC::Channel* transport,
base::ProcessHandle parent,
MessageLoop* worker)
{
if (atexit(DeleteChildActor))
fail("can't install atexit() handler");
switch (IPDLUnitTest()) {
//-----------------------------------------------------------------------------
//===== TEMPLATED =====

View File

@ -58,6 +58,12 @@ def main(argv):
''' case %s:
return "%s";'''%(t, t) for t in unittests ])
parent_delete_cases = '\n'.join([
''' case %s: {
delete reinterpret_cast<mozilla::_ipdltest::%sParent*>(gParentActor);
return;
}
'''% (t, t) for t in unittests ])
parent_main_cases = '\n'.join([
''' case %s: {
@ -69,6 +75,13 @@ def main(argv):
}
'''% (t, t, t, t) for t in unittests ])
child_delete_cases = '\n'.join([
''' case %s: {
delete reinterpret_cast<mozilla::_ipdltest::%sChild*>(gChildActor);
return;
}
'''% (t, t) for t in unittests ])
child_init_cases = '\n'.join([
''' case %s: {
@ -87,7 +100,9 @@ def main(argv):
ENUM_VALUES=enum_values, LAST_ENUM=last_enum,
STRING_TO_ENUMS=string_to_enums,
ENUM_TO_STRINGS=enum_to_strings,
PARENT_DELETE_CASES=parent_delete_cases,
PARENT_MAIN_CASES=parent_main_cases,
CHILD_DELETE_CASES=child_delete_cases,
CHILD_INIT_CASES=child_init_cases))
templatefile.close()

View File

@ -3650,5 +3650,7 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
CrashReporter::UnsetExceptionHandler();
#endif
XRE_DeinitCommandLine();
return NS_FAILED(rv) ? 1 : 0;
}

View File

@ -336,7 +336,7 @@ XRE_InitChildProcess(int aArgc,
}
NS_LogTerm();
return NS_OK;
return XRE_DeinitCommandLine();
}
MessageLoop*
@ -416,7 +416,7 @@ XRE_InitParentProcess(int aArgc,
}
}
return NS_OK;
return XRE_DeinitCommandLine();
}
#ifdef MOZ_IPDL_TESTS
@ -528,7 +528,7 @@ XRE_ShutdownTestShell()
nsresult
XRE_InitCommandLine(int aArgc, char* aArgv[])
{
nsresult rv = NS_OK;
nsresult rv = NS_OK;
#if defined(MOZ_IPC)
@ -560,12 +560,25 @@ XRE_InitCommandLine(int aArgc, char* aArgv[])
NS_ASSERTION(!CommandLine::IsInitialized(), "Bad news!");
CommandLine::Init(aArgc, canonArgs);
for (int i = 0; i < aArgc; ++i)
free(canonArgs[i]);
delete[] canonArgs;
#endif
#endif
return rv;
}
nsresult
XRE_DeinitCommandLine()
{
nsresult rv = NS_OK;
#if defined(MOZ_IPC)
CommandLine::Terminate();
#endif
return rv;
}
GeckoProcessType
XRE_GetProcessType()

View File

@ -475,6 +475,9 @@ XRE_API(nsresult,
XRE_API(nsresult,
XRE_InitCommandLine, (int aArgc, char* aArgv[]))
XRE_API(nsresult,
XRE_DeinitCommandLine, ())
class MessageLoop;
XRE_API(void,