Skip to content

Commit

Permalink
Memleak in HPDirectJet printer transport
Browse files Browse the repository at this point in the history
CID 605747
  • Loading branch information
stpere committed Jul 1, 2015
1 parent 385d907 commit ee1265c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 7 additions & 3 deletions src/add-ons/print/transports/hp_jetdirect/SetupWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,32 @@ 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)
port = 9100;

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;
};

char str[256];
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");
Expand Down

0 comments on commit ee1265c

Please sign in to comment.