removed potential memory deref errors

This commit is contained in:
rickg%netscape.com 1999-07-17 11:08:28 +00:00
parent db57ad2df6
commit 465272c799
6 changed files with 76 additions and 60 deletions

View File

@ -99,7 +99,9 @@ protected:
nsresult NS_NewRobotSink(nsIRobotSink** aInstancePtrResult)
{
RobotSink* it = new RobotSink();
return it->QueryInterface(kIRobotSinkIID, (void**) aInstancePtrResult);
if(it)
return it->QueryInterface(kIRobotSinkIID, (void**) aInstancePtrResult);
return NS_OK;
}
RobotSink::RobotSink()

View File

@ -16,9 +16,11 @@ extern "C" NS_EXPORT int DebugRobot(nsVoidArray * workList, nsIWebShell * ww);
int main(int argc, char **argv)
{
nsVoidArray * gWorkList = new nsVoidArray();
int i;
for (i = 1; i < argc; i++) {
gWorkList->AppendElement(new nsString(argv[i]));
if(gWorkList) {
int i;
for (i = 1; i < argc; i++) {
gWorkList->AppendElement(new nsString(argv[i]));
}
}
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);

View File

@ -242,34 +242,36 @@ PageGrabber::Grab(const nsString& aURL)
// Start the URL load...
StreamToFile* copier = new StreamToFile(fp);
NS_ADDREF(copier);
if(copier) {
NS_ADDREF(copier);
#ifndef NECKO
rv = url->Open(copier);
#else
rv = channel->AsyncRead(0, -1, nsnull, copier);
#endif // NECKO
#ifndef NECKO
rv = url->Open(copier);
#else
rv = channel->AsyncRead(0, -1, nsnull, copier);
#endif // NECKO
if (NS_OK != rv) {
NS_RELEASE(copier);
NS_RELEASE(url);
return rv;
}
// Enter the message pump to allow the URL load to proceed.
#ifdef XP_PC
MSG msg;
while ( !copier->IsDone() ) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
if (NS_OK != rv) {
NS_RELEASE(copier);
NS_RELEASE(url);
return rv;
}
}
#endif
// Enter the message pump to allow the URL load to proceed.
#ifdef XP_PC
MSG msg;
while ( !copier->IsDone() ) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif
PRBool error = copier->HaveError();
PRBool error = copier->HaveError();
NS_RELEASE(copier);
}
NS_RELEASE(url);
NS_RELEASE(copier);
return error ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
@ -285,9 +287,11 @@ main(int argc, char **argv)
return -1;
}
PageGrabber* grabber = new PageGrabber();
grabber->Init(argv[2]);
if (NS_OK != grabber->Grab(argv[1])) {
return -1;
if(grabber) {
grabber->Init(argv[2]);
if (NS_OK != grabber->Grab(argv[1])) {
return -1;
}
}
return 0;
}

View File

@ -99,7 +99,9 @@ protected:
nsresult NS_NewRobotSink(nsIRobotSink** aInstancePtrResult)
{
RobotSink* it = new RobotSink();
return it->QueryInterface(kIRobotSinkIID, (void**) aInstancePtrResult);
if(it)
return it->QueryInterface(kIRobotSinkIID, (void**) aInstancePtrResult);
return NS_OK;
}
RobotSink::RobotSink()

View File

@ -16,9 +16,11 @@ extern "C" NS_EXPORT int DebugRobot(nsVoidArray * workList, nsIWebShell * ww);
int main(int argc, char **argv)
{
nsVoidArray * gWorkList = new nsVoidArray();
int i;
for (i = 1; i < argc; i++) {
gWorkList->AppendElement(new nsString(argv[i]));
if(gWorkList) {
int i;
for (i = 1; i < argc; i++) {
gWorkList->AppendElement(new nsString(argv[i]));
}
}
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);

View File

@ -242,34 +242,36 @@ PageGrabber::Grab(const nsString& aURL)
// Start the URL load...
StreamToFile* copier = new StreamToFile(fp);
NS_ADDREF(copier);
if(copier) {
NS_ADDREF(copier);
#ifndef NECKO
rv = url->Open(copier);
#else
rv = channel->AsyncRead(0, -1, nsnull, copier);
#endif // NECKO
#ifndef NECKO
rv = url->Open(copier);
#else
rv = channel->AsyncRead(0, -1, nsnull, copier);
#endif // NECKO
if (NS_OK != rv) {
NS_RELEASE(copier);
NS_RELEASE(url);
return rv;
}
// Enter the message pump to allow the URL load to proceed.
#ifdef XP_PC
MSG msg;
while ( !copier->IsDone() ) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
if (NS_OK != rv) {
NS_RELEASE(copier);
NS_RELEASE(url);
return rv;
}
}
#endif
// Enter the message pump to allow the URL load to proceed.
#ifdef XP_PC
MSG msg;
while ( !copier->IsDone() ) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif
PRBool error = copier->HaveError();
PRBool error = copier->HaveError();
NS_RELEASE(copier);
}
NS_RELEASE(url);
NS_RELEASE(copier);
return error ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
@ -285,9 +287,11 @@ main(int argc, char **argv)
return -1;
}
PageGrabber* grabber = new PageGrabber();
grabber->Init(argv[2]);
if (NS_OK != grabber->Grab(argv[1])) {
return -1;
if(grabber) {
grabber->Init(argv[2]);
if (NS_OK != grabber->Grab(argv[1])) {
return -1;
}
}
return 0;
}