delete vs. delete[] vs. free fixes.

Thanks to "Bruce Mitchener, Jr." <bruce@cybersight.com for finding all these
and making patches.


git-svn-id: svn://10.0.0.236/trunk@25592 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ramiro%netscape.com 1999-03-30 05:26:59 +00:00
parent abde8984f1
commit 52ef5e02cd
24 changed files with 87 additions and 55 deletions

View File

@ -120,6 +120,7 @@ main(int argc, char *argv[])
}
char *value = v.ToNewCString();
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
delete[] value;
i++;
}

View File

@ -658,7 +658,7 @@ static void WriteFromOstrstream(ostrstream& aIn, nsString& aOutputString)
// in ostrstreams if you call the str() function
// then you are responsible for deleting the string
delete strData;
delete[] strData;
}
#endif

View File

@ -87,7 +87,7 @@ DeviceContextImpl :: ~DeviceContextImpl()
if (nsnull != mGammaTable)
{
delete mGammaTable;
delete[] mGammaTable;
mGammaTable = nsnull;
}

View File

@ -863,7 +863,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode, ostream& a
char* buffer = new char[size+1];
data.ToCString(buffer,size+1);
aStream << buffer;
delete buffer;
delete[] buffer;
}
else
{

View File

@ -234,10 +234,11 @@ nsIWin32LocaleImpl::GetPlatformLocale(const nsString* locale,LCID* winLCID)
{
*winLCID = MAKELCID(language_list[i].lang_code,SORT_DEFAULT);
delete[] locale_string;
return NS_OK;
}
}
delete[] locale_string;
return NS_ERROR_FAILURE;
}

View File

@ -426,7 +426,7 @@ nsresult nsHttpUrlImpl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
if (!isAbsolute) {
// relative spec
if (nsnull == aURL) {
delete cSpec;
delete[] cSpec;
NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
@ -447,7 +447,7 @@ nsresult nsHttpUrlImpl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
// Strip out old tail component and put in the new one
char* dp = PL_strrchr(uFile, '/');
if (!dp) {
delete cSpec;
delete[] cSpec;
NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
}
@ -533,7 +533,7 @@ nsresult nsHttpUrlImpl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
}
}
} else {
delete cSpec;
delete[] cSpec;
NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
@ -617,7 +617,7 @@ nsresult nsHttpUrlImpl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
}
//printf("protocol='%s' host='%s' file='%s'\n", mProtocol, mHost, mFile);
delete cSpec;
delete[] cSpec;
NS_UNLOCK_INSTANCE();
return NS_OK;

View File

@ -821,7 +821,7 @@ nsNetlibService::SetProxyHTTP(nsString& aProxyHTTP) {
return NS_FALSE;
csPort = nsSPort.ToNewCString();
if (!csPort) {
delete proxy;
delete[] proxy;
return NS_FALSE;
}
@ -833,8 +833,8 @@ nsNetlibService::SetProxyHTTP(nsString& aProxyHTTP) {
if ( PREF_OK != PREF_SetIntPref(pref_proxyHttpPort, port) ) {
rv = NS_FALSE;
}
delete proxy;
delete csPort;
delete[] proxy;
delete[] csPort;
NET_SelectProxyStyle(PROXY_STYLE_MANUAL);

View File

@ -1139,7 +1139,7 @@ NET_I_XP_FileOpen(const char * name, XP_FileType type, const XP_FilePerm perm)
rv = fileMgr->OpenFile( (aName ? aName : name), mode, &nsFp);
if (aName)
delete aName;
delete[] aName;
if (NS_OK != rv) {
return NULL;
}
@ -1275,7 +1275,7 @@ NET_I_XP_FileRemove(const char * name, XP_FileType type)
rv = fileMgr->FileRemove((aName ? aName : name));
if (aName)
delete aName;
delete[] aName;
if (rv != NS_OK)
return -1;
@ -1305,16 +1305,19 @@ NET_I_XP_Stat(const char * name, XP_StatStruct * info, XP_FileType type)
if (!fileMgr) {
if (NS_NewINetFile(&fileMgr, nsnull) != NS_OK) {
delete[] newName;
return NULL;
}
}
rv = fileMgr->GetFilePath(newName, &path);
if (rv != NS_OK)
if (rv != NS_OK) {
delete[] newName;
return -1;
}
status = PR_GetFileInfo(path, &fileInfo);
PR_Free(path);
delete newName;
delete[] newName;
if (status == PR_SUCCESS) {
// transfer the pr stat info over to the xp stat object.
// right now just moving over the size.

View File

@ -134,7 +134,7 @@ NS_IMETHODIMP TestConsumer::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
nsAutoString str(aMsg);
char* c = str.ToNewCString();
fputs(c, stdout);
free(c);
delete[] c;
fputs("\n", stdout);
}

View File

@ -220,7 +220,7 @@ NS_IMETHODIMP TestConsumer::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
nsString str(aMsg);
char* c = str.ToNewCString();
fputs(c, stdout);
free(c);
delete[] c;
fputs("\n", stdout);
}

View File

@ -863,7 +863,7 @@ void nsHTMLContentSinkStream::AddStartTag(const nsIParserNode& aNode, ostream& a
char* buffer = new char[size+1];
data.ToCString(buffer,size+1);
aStream << buffer;
delete buffer;
delete[] buffer;
}
else
{

View File

@ -303,7 +303,7 @@ STDAPI DllRegisterServer(void)
// Free up memory...
if (WebShellCLSID) {
delete WebShellCLSID;
delete[] WebShellCLSID;
}
return NOERROR;
@ -373,7 +373,7 @@ STDAPI DllUnregisterServer(void)
// Free up memory...
if (WebShellCLSID) {
delete WebShellCLSID;
delete[] WebShellCLSID;
}
return NOERROR;

View File

@ -47,7 +47,7 @@
#define NS_FREE_STR_BUF(varName) \
if (! _ns_smallBufUsed) \
delete varName;
delete[] varName;
// Create temporary char[] macro
//
@ -73,7 +73,7 @@
#define NS_FREE_CHAR_BUF(aBuf) \
if (! _ns_smallBufUsed) \
delete aBuf;
delete[] aBuf;
#endif // NSStringUtil

View File

@ -47,7 +47,7 @@
#define NS_FREE_STR_BUF(varName) \
if (! _ns_smallBufUsed) \
delete varName;
delete[] varName;
// Create temporary char[] macro
//
@ -73,7 +73,7 @@
#define NS_FREE_CHAR_BUF(aBuf) \
if (! _ns_smallBufUsed) \
delete aBuf;
delete[] aBuf;
#endif // NSStringUtil
#endif // NSStringUtil

View File

@ -92,11 +92,11 @@ PRBool nsFileWidget::Show()
VERIFY(::GetCurrentDirectory(MAX_PATH, newCurrentDirectory) > 0);
mDisplayDirectory.SetLength(0);
mDisplayDirectory.Append(newCurrentDirectory);
delete newCurrentDirectory;
delete[] newCurrentDirectory;
VERIFY(::SetCurrentDirectory(currentDirectory));
delete currentDirectory;
delete[] currentDirectory;
// Clean up filter buffers
delete[] filterBuffer;

View File

@ -73,7 +73,7 @@
#define NS_FREE_CHAR_BUF(aBuf) \
if (! _ns_smallBufUsed) \
delete aBuf;
delete[] aBuf;
#endif // NSStringUtil
#endif // NSStringUtil

View File

@ -146,7 +146,7 @@ nsHTToolbarDataModel :: RequestImage(nsString& reqUrl) const
(nsIImageRequestObserver*)this,
NULL, 0, 0,
0);
delete url;
delete[] url;
return request;
} // RequestImage

View File

@ -304,7 +304,7 @@ nsIImageRequest* nsHTTreeDataModel::RequestImage(nsString& reqUrl) const
(nsIImageRequestObserver*)this,
NULL, 0, 0,
0);
delete url;
delete[] url;
return request;
}

View File

@ -183,7 +183,7 @@ nsIImageRequest* nsHTTreeItem::RequestImage(nsString& reqUrl) const
(nsIImageRequestObserver*)this,
NULL, 0, 0,
0);
delete url;
delete[] url;
return request;
}

View File

@ -85,7 +85,7 @@ nsTransferable::~nsTransferable()
delete mStrCache;
}
if (mDataPtr) {
delete mDataPtr;
delete[] mDataPtr;
}
}
@ -159,7 +159,7 @@ NS_IMETHODIMP nsTransferable::IsDataFlavorSupported(nsIDataFlavor * aDataFlavor)
NS_IMETHODIMP nsTransferable::GetTransferData(nsIDataFlavor * aDataFlavor, void ** aData, PRUint32 * aDataLen)
{
if (mDataPtr) {
delete mDataPtr;
delete[] mDataPtr;
}
nsAutoString mimeInQuestion;

View File

@ -223,7 +223,7 @@ void listSelfTest(FILE * fd, char * aTitle, nsIListWidget * listBox) {
fprintf(fd, "\nTesting GetSelectedItem\n");
fprintf(fd, "\tSelection should be [%s] is [%s] Test: [%s]\n",
item4, selStr, eval(!strcmp(item4, selStr))); fflush(fd);
if (nsnull != selStr) delete selStr;
if (nsnull != selStr) delete[] selStr;
int sel = listBox->GetSelectedIndex();
fprintf(fd, "\nTesting GetSelectedIndex\n");fflush(fd);
@ -238,7 +238,7 @@ void listSelfTest(FILE * fd, char * aTitle, nsIListWidget * listBox) {
listBox->GetItemAt(buf, 4);
selStr = buf.ToNewCString();
fprintf(fd, "\nTesting GetItemAt\n\tItem %d should be [%s] is [%s] Test: [%s]\n", inx, item4, selStr, eval(strcmp(selStr, item4) == 0)); fflush(fd);
if (nsnull != selStr) delete selStr;
if (nsnull != selStr) delete[] selStr;
listBox->SelectItem(2);
inx = listBox->GetSelectedIndex();
@ -252,7 +252,7 @@ void listSelfTest(FILE * fd, char * aTitle, nsIListWidget * listBox) {
fprintf(fd, "Item %d [%s]\n", i, str);fflush(fd);
if (nsnull != str) delete str;
if (nsnull != str) delete[] str;
}
fprintf(fd, "Removing Item #4\n");fflush(fd);
listBox->RemoveItemAt(4);
@ -267,7 +267,7 @@ void listSelfTest(FILE * fd, char * aTitle, nsIListWidget * listBox) {
fprintf(fd, "Item %d [%s]\n", i, str);fflush(fd);
if (nsnull != str) delete str;
if (nsnull != str) delete[] str;
}
listBox->Deselect();
fprintf(fd, "\nTesting Deselect\n\t Selected Item [%d] Test:[%s]\n", (int)listBox->GetSelectedIndex(), (-1 == (int)listBox->GetSelectedIndex()?"PASSED":"FAILED")); fflush(fd);
@ -308,7 +308,7 @@ void textSelfTest(FILE * fd, char * aTitle, nsITextWidget * aTextWidget) {
char * s2 = "1xxx234567890";
fprintf(fd, "Tested InsertText Test [%s] is [%s] [%s]\n", s2, s, eval(!strcmp(s2, s)));
fprintf(fd, "Tested InsertText Test [%s]\n", s);
delete s;
delete[] s;
}
@ -333,7 +333,7 @@ void multiListSelfTest(FILE * fd, char * aTitle, nsIListBox * listBox) {
selStr = buf.ToNewCString();
fprintf(fd, "\nTesting GetItemAt\n\tItem %d should be [%s] is [%s] Test: [%s]\n", inx, item4, selStr,
eval(strcmp(selStr, item4) == 0)); fflush(fd);
if (nsnull != selStr) delete selStr;
if (nsnull != selStr) delete[] selStr;
multi->Deselect();
@ -356,7 +356,7 @@ void multiListSelfTest(FILE * fd, char * aTitle, nsIListBox * listBox) {
selStr = selItem.ToNewCString();
fprintf(fd, "\nTesting GetSelectedItem\n\t is [%s] should be [%s] Test: [%s]\n",
selStr, item0, eval(!strcmp(selStr, item0))); fflush(fd);
if (nsnull != selStr) delete selStr;*/
if (nsnull != selStr) delete[] selStr;*/
int status = 1;
count = multi->GetSelectedCount();
@ -387,7 +387,7 @@ void multiListSelfTest(FILE * fd, char * aTitle, nsIListBox * listBox) {
fprintf(fd, "Item %d [%s]\n", i, str);fflush(fd);
if (nsnull != str) delete str;
if (nsnull != str) delete[] str;
}
fprintf(fd, "Removing Item #4\n");fflush(fd);
multi->RemoveItemAt(4);
@ -402,7 +402,7 @@ void multiListSelfTest(FILE * fd, char * aTitle, nsIListBox * listBox) {
fprintf(fd, "Item %d [%s]\n", i, str);fflush(fd);
if (nsnull != str) delete str;
if (nsnull != str) delete[] str;
}
fprintf(fd, "Done with Mulitple List Box\n");
}
@ -508,7 +508,7 @@ nsEventStatus PR_CALLBACK GenericListHandleEvent(nsGUIEvent *aEvent, char * aTit
statusText->SetText(str,actualSize);
gFailedMsg = "List::RemoveItemAt && FindItem";
}
delete title;
delete[] title;
//NS_RELEASE(btn);
}
return nsEventStatus_eIgnore;
@ -598,7 +598,7 @@ nsEventStatus PR_CALLBACK MultiListBoxTestHandleEvent(nsGUIEvent *aEvent)
statusText->SetText(str,actualSize);
gFailedMsg = "Multi-List::FindItem && RemoveItemAt";
}
delete title;
delete[] title;
//NS_RELEASE(btn);
}
return nsEventStatus_eIgnore;
@ -769,7 +769,7 @@ nsEventStatus PR_CALLBACK GenericTextTestHandleEvent(char *aTitle,
statusText->SetText(str,actualSize);
gFailedMsg = "nsITextWidget::SetSelection";
}
delete title;
delete[] title;
//NS_RELEASE(btn);
}
return nsEventStatus_eIgnore;
@ -807,7 +807,7 @@ nsEventStatus PR_CALLBACK ButtonTestHandleEvent(nsGUIEvent *aEvent)
gFailedMsg = "nsIWidget::Show(TRUE)";
}
delete title;
delete[] title;
//NS_RELEASE(btn);
}
@ -1031,8 +1031,10 @@ nsEventStatus PR_CALLBACK HandleFileButtonEvent(nsGUIEvent *aEvent)
if (result) {
nsString file;
fileWidget->GetFile(file);
printf("file widget contents %s\n", file.ToNewCString());
statusText->SetText(file.ToNewCString(),actualSize);
char* filestr = file.ToNewCString();
printf("file widget contents %s\n", filestr);
statusText->SetText(filestr,actualSize);
delete[] filestr;
}
else
statusText->SetText("Cancel selected",actualSize);

View File

@ -120,6 +120,7 @@ main(int argc, char *argv[])
}
char *value = v.ToNewCString();
cout << "\"" << i << "\"=\"" << value << "\"" << endl;
delete[] value;
i++;
}

View File

@ -467,6 +467,8 @@ nsBrowserAppCore::LoadUrl(const nsString& aUrl)
/* Ask nsWebShell to load the URl */
mContentAreaWebShell->LoadURL(nsString(urlstr), nsnull, nsnull);
delete[] urlstr;
return NS_OK;
}
@ -538,7 +540,11 @@ nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
webShell->GetName( &name);
nsAutoString str(name);
if (APP_DEBUG) printf("Attaching to WebShellWindow[%s]\n", str.ToNewCString());
if (APP_DEBUG) {
char* cstr = str.ToNewCString();
printf("Attaching to WebShellWindow[%s]\n", cstr);
delete[] cstr;
}
nsIWebShellContainer * webShellContainer;
webShell->GetContainer(webShellContainer);
@ -810,7 +816,11 @@ nsBrowserAppCore::ExecuteScript(nsIScriptContext * aContext, const nsString& aSc
const char* url = "";
PRBool isUndefined = PR_FALSE;
nsString rVal;
if (APP_DEBUG) printf("Executing [%s]\n", aScript.ToNewCString());
if (APP_DEBUG) {
char* script_str = aScript.ToNewCString();
printf("Executing [%s]\n", script_str);
delete[] script_str;
}
aContext->EvaluateString(aScript, url, 0, rVal, &isUndefined);
}
return NS_OK;

View File

@ -124,7 +124,9 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
nsEditorAppCore::nsEditorAppCore()
{
if (APP_DEBUG) printf("Created nsEditorAppCore\n");
#ifdef APP_DEBUG
printf("Created nsEditorAppCore\n");
#endif
mScriptObject = nsnull;
mToolbarWindow = nsnull;
@ -405,7 +407,11 @@ nsEditorAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
webShell->GetName( &name);
nsAutoString str(name);
if (APP_DEBUG) printf("Attaching to WebShellWindow[%s]\n", str.ToNewCString());
#ifdef APP_DEBUG
char* cstr = str.ToNewCString();
printf("Attaching to WebShellWindow[%s]\n", str.ToNewCString());
delete[] cstr;
#endif
nsIWebShellContainer * webShellContainer;
webShell->GetContainer(webShellContainer);
@ -542,7 +548,9 @@ done:
void GenerateBarItem(FILE * fd, char * aFileName, const nsString & aDesc, void * aData, PRUint32 aLen)
{
fprintf(fd, "<titledbutton src=\"resource:/res/toolbar/TB_PersonalIcon.gif\" align=\"right\" value=");
fprintf(fd, "\"%s\"", aDesc.ToNewCString());
char* desc_str= aDesc.ToNewCString();
fprintf(fd, "\"%s\"", desc_str);
delete[] desc_str;
fprintf(fd, " onclick=\"LoadURL('%s')\"/>\n", aFileName);
char name[256];
@ -842,7 +850,13 @@ nsEditorAppCore::ExecuteScript(nsIScriptContext * aContext, const nsString& aScr
const char* url = "";
PRBool isUndefined = PR_FALSE;
nsString rVal;
if (APP_DEBUG) printf("Executing [%s]\n", aScript.ToNewCString());
#ifdef APP_DEBUG
char* script_str = aScript.ToNewCString();
printf("Executing [%s]\n", aScript.ToNewCString());
delete[] script_str;
#endif
aContext->EvaluateString(aScript, url, 0, rVal, &isUndefined);
}
return NS_OK;