Fixes crash in CrashReporter on child process shutdown, bug 548810. r=ted

This commit is contained in:
Benedict Hsieh 2010-03-11 17:17:35 -08:00
Родитель 55b7305f9e
Коммит 80dd558623
1 изменённых файлов: 19 добавлений и 18 удалений

Просмотреть файл

@ -1158,13 +1158,13 @@ static PLDHashOperator EnumerateChildAnnotations(const nsACString& key,
return PL_DHASH_NEXT;
}
nsIFileOutputStream* extraStream =
reinterpret_cast<nsIFileOutputStream*>(userData);
PRUint32 written;
extraStream->Write(key.BeginReading(), key.Length(), &written);
extraStream->Write("=", 1, &written);
extraStream->Write(entry.BeginReading(), entry.Length(), &written);
extraStream->Write("\n", 1, &written);
PRFileDesc* fd =
reinterpret_cast<PRFileDesc*>(userData);
PR_Write(fd, key.BeginReading(), key.Length());
PR_Write(fd, "=", 1);
PR_Write(fd, entry.BeginReading(), entry.Length());
PR_Write(fd, "\n", 1);
return PL_DHASH_NEXT;
}
@ -1211,10 +1211,12 @@ OnChildProcessDumpRequested(void* aContext,
#endif
// Get an .extra file with the same base name as the .dmp file
nsCOMPtr<nsIFile> extraFile;
nsresult rv = lf->Clone(getter_AddRefs(extraFile));
nsCOMPtr<nsIFile> file;
nsresult rv = lf->Clone(getter_AddRefs(file));
if (NS_FAILED(rv))
return;
nsCOMPtr<nsILocalFile> extraFile = do_QueryInterface(file);
nsAutoString leafName;
rv = extraFile->GetLeafName(leafName);
@ -1228,23 +1230,22 @@ OnChildProcessDumpRequested(void* aContext,
return;
// Now write out the annotations to it
nsCOMPtr<nsIFileOutputStream> stream =
do_CreateInstance("@mozilla.org/network/file-output-stream;1");
rv = stream->Init(extraFile, -1, 0600, 0);
PRFileDesc* fd;
rv = extraFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
0600, &fd);
if (NS_FAILED(rv))
return;
crashReporterAPIData_Hash->EnumerateRead(EnumerateChildAnnotations,
stream.get());
fd);
// Add CrashTime to extra data
time_t crashTime = time(NULL);
char crashTimeString[32];
XP_TTOA(crashTime, crashTimeString, 10);
PRUint32 written;
stream->Write(kCrashTimeParameter, kCrashTimeParameterLen, &written);
stream->Write(crashTimeString, strlen(crashTimeString), &written);
stream->Write("\n", 1, &written);
stream->Close();
PR_Write(fd, kCrashTimeParameter, kCrashTimeParameterLen);
PR_Write(fd, crashTimeString, strlen(crashTimeString));
PR_Write(fd, "\n", 1);
PR_Close(fd);
bool doReport = true;
char* e = getenv("MOZ_CRASHREPORTER_NO_REPORT");