diff --git a/src/add-ons/print/transports/hp_jetdirect/HPJetDirectTransport.cpp b/src/add-ons/print/transports/hp_jetdirect/HPJetDirectTransport.cpp index 71f3f72b8f..7ade202185 100644 --- a/src/add-ons/print/transports/hp_jetdirect/HPJetDirectTransport.cpp +++ b/src/add-ons/print/transports/hp_jetdirect/HPJetDirectTransport.cpp @@ -52,11 +52,13 @@ HPJetDirectPort::HPJetDirectPort(BDirectory* printer, BMessage *msg) printf("fPort = %d\n", fPort); - fEndpoint = new BNetEndpoint(SOCK_STREAM); - if ((fReady = fEndpoint->InitCheck()) != B_OK) { + fEndpoint = new(std::nothrow) BNetEndpoint(SOCK_STREAM); + if (fEndpoint == NULL || (fReady = fEndpoint->InitCheck()) != B_OK) { BAlert *alert = new BAlert("", "Fail to create the NetEndpoint!", "OK"); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); + delete fEndpoint; + fEndpoint = NULL; return; } diff --git a/src/add-ons/print/transports/hp_jetdirect/SetupWindow.cpp b/src/add-ons/print/transports/hp_jetdirect/SetupWindow.cpp index 6a2f89ff23..b0f831431e 100644 --- a/src/add-ons/print/transports/hp_jetdirect/SetupWindow.cpp +++ b/src/add-ons/print/transports/hp_jetdirect/SetupWindow.cpp @@ -126,8 +126,8 @@ bool SetupView::CheckSetup() { if (*fServerAddress->Text() && *fQueuePort->Text()) { - BNetEndpoint* ep = new BNetEndpoint(SOCK_STREAM); - if (ep->InitCheck() == B_NO_ERROR) { + BNetEndpoint* ep = new(std::nothrow) BNetEndpoint(SOCK_STREAM); + if (ep != NULL && ep->InitCheck() == B_NO_ERROR) { uint16 port = atoi(fQueuePort->Text()); if (! port) @@ -135,10 +135,12 @@ SetupView::CheckSetup() if (ep->Connect(fServerAddress->Text(), port) != B_OK) { BString text; - text << "Failed to connect to " << fServerAddress->Text() << ":" << (int) port << "!"; + text << "Failed to connect to " << fServerAddress->Text() + << ":" << (int) port << "!"; BAlert* alert = new BAlert("", text.String(), "OK"); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); + delete ep; return false; }; @@ -146,8 +148,10 @@ SetupView::CheckSetup() sprintf(str, "%s:%d", fServerAddress->Text(), port); fPrinterDirectory->WriteAttr("transport_address", B_STRING_TYPE, 0, str, strlen(str) + 1); + delete ep; return true; }; + delete ep; }; BAlert* alert = new BAlert("", "Please input parameters.", "OK");