Fixed memory leak in ToString()

This commit is contained in:
troy%netscape.com 1998-12-29 01:03:26 +00:00
Родитель 4d29219473
Коммит de15a8198e
2 изменённых файлов: 15 добавлений и 15 удалений

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

@ -883,37 +883,37 @@ nsresult nsHttpUrlImpl::SetPostData(nsIInputStream* input)
nsresult nsHttpUrlImpl::ToString(PRUnichar* *unichars) const nsresult nsHttpUrlImpl::ToString(PRUnichar* *unichars) const
{ {
nsString& aString = *new nsString(); nsAutoString string;
NS_LOCK_INSTANCE(); NS_LOCK_INSTANCE();
// XXX Special-case javascript: URLs for the moment. // XXX Special-case javascript: URLs for the moment.
// This code will go away when we actually start doing // This code will go away when we actually start doing
// protocol-specific parsing. // protocol-specific parsing.
if (PL_strcmp(mProtocol, "javascript") == 0) { if (PL_strcmp(mProtocol, "javascript") == 0) {
aString.SetString(mSpec); string.SetString(mSpec);
} else { } else {
aString.SetLength(0); string.SetLength(0);
aString.Append(mProtocol); string.Append(mProtocol);
aString.Append("://"); string.Append("://");
if (nsnull != mHost) { if (nsnull != mHost) {
aString.Append(mHost); string.Append(mHost);
if (0 < mPort) { if (0 < mPort) {
aString.Append(':'); string.Append(':');
aString.Append(mPort, 10); string.Append(mPort, 10);
} }
} }
aString.Append(mFile); string.Append(mFile);
if (nsnull != mRef) { if (nsnull != mRef) {
aString.Append('#'); string.Append('#');
aString.Append(mRef); string.Append(mRef);
} }
if (nsnull != mSearch) { if (nsnull != mSearch) {
aString.Append('?'); string.Append('?');
aString.Append(mSearch); string.Append(mSearch);
} }
} }
NS_UNLOCK_INSTANCE(); NS_UNLOCK_INSTANCE();
*unichars = aString.ToNewUnicode(); *unichars = string.ToNewUnicode();
return NS_OK; return NS_OK;
} }

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

@ -953,7 +953,7 @@ NS_NET nsresult NS_MakeAbsoluteURL(nsIURL* aURL,
err = url->ToString(&str); err = url->ToString(&str);
if (err) goto done; if (err) goto done;
string = new nsString(str); string = new nsString(str);
delete str; delete []str;
if (string == NULL) if (string == NULL)
err = NS_ERROR_OUT_OF_MEMORY; err = NS_ERROR_OUT_OF_MEMORY;
else else