зеркало из https://github.com/mozilla/pjs.git
Fix potential memory leaks in nsDataChannel. Bug 138081, r=timeless,
sr=darin
This commit is contained in:
Родитель
5dad07f3db
Коммит
141a9f5415
|
@ -179,19 +179,26 @@ nsDataChannel::ParseData() {
|
|||
nsCAutoString dataBuf(comma+1);
|
||||
dataBuf.StripWhitespace();
|
||||
dataBuffer = ToNewCString(dataBuf);
|
||||
if (!dataBuffer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
cleanup = PR_TRUE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> bufInStream;
|
||||
nsCOMPtr<nsIOutputStream> bufOutStream;
|
||||
writeData* dataToWrite = nsnull;
|
||||
PRUint32 dataLen = PL_strlen(dataBuffer);
|
||||
|
||||
rv = NS_NewPipe(getter_AddRefs(bufInStream), getter_AddRefs(bufOutStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv))
|
||||
goto cleanup;
|
||||
|
||||
PRUint32 dataLen = PL_strlen(dataBuffer);
|
||||
PRUint32 wrote;
|
||||
writeData *dataToWrite = (writeData*)nsMemory::Alloc(sizeof(writeData));
|
||||
if (!dataToWrite) return NS_ERROR_OUT_OF_MEMORY;
|
||||
dataToWrite = (writeData*)nsMemory::Alloc(sizeof(writeData));
|
||||
if (!dataToWrite) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (lBase64) {
|
||||
*base64 = 'b';
|
||||
|
@ -206,8 +213,14 @@ nsDataChannel::ParseData() {
|
|||
}
|
||||
resultLen = ((resultLen * 3) / 4);
|
||||
|
||||
// XXX PL_Base64Decode will return a null pointer for decoding
|
||||
// errors. Since those are more likely than out-of-memory,
|
||||
// should we return NS_ERROR_MALFORMED_URI instead?
|
||||
char * decodedData = PL_Base64Decode(dataBuffer, dataLen, nsnull);
|
||||
if (!decodedData) return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!decodedData) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dataToWrite->dataLen = resultLen;
|
||||
dataToWrite->data = decodedData;
|
||||
|
@ -221,19 +234,26 @@ nsDataChannel::ParseData() {
|
|||
|
||||
rv = bufOutStream->WriteSegments(nsReadData, dataToWrite, dataLen, &wrote);
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv))
|
||||
goto cleanup;
|
||||
|
||||
// Initialize the content length of the data...
|
||||
mContentLength = dataToWrite->dataLen;
|
||||
|
||||
rv = bufInStream->QueryInterface(NS_GET_IID(nsIInputStream), getter_AddRefs(mDataStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv))
|
||||
goto cleanup;
|
||||
|
||||
*comma = ',';
|
||||
|
||||
rv = NS_OK;
|
||||
|
||||
cleanup:
|
||||
if (dataToWrite)
|
||||
nsMemory::Free(dataToWrite);
|
||||
if (cleanup) nsMemory::Free(dataBuffer);
|
||||
return NS_OK;
|
||||
if (cleanup)
|
||||
nsMemory::Free(dataBuffer);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
|
|
Загрузка…
Ссылка в новой задаче