Memleak in HPDirectJet printer transport

CID 605747
This commit is contained in:
Philippe Saint-Pierre
2015-07-01 19:32:54 -04:00
parent 385d90724e
commit ee1265c58e
2 changed files with 11 additions and 5 deletions
@@ -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;
}
@@ -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");