Skip to content

Commit

Permalink
micro-changes. calling free() on everything malloc()'d
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdaley92 committed Feb 26, 2017
1 parent d2320df commit 3af6658
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Binary file modified bin/tomcat.exe
Binary file not shown.
25 changes: 15 additions & 10 deletions src/scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,33 +163,34 @@ int ping_host(char *host, int timeout, int *latency, char *info) {
if (hIcmpFile == INVALID_HANDLE_VALUE) {
if (DEBUG) {
fprintf(stderr, "\tUnable to open handle.\n");
fprintf(stderr, "IcmpCreatefile returned error: %ld\n", GetLastError() );
fprintf(stderr, "IcmpCreatefile returned error: %ld\n", GetLastError());
}
return 1;
}

ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
ReplyBuffer = (VOID*) malloc(ReplySize);
if (ReplyBuffer == NULL) {
if (DEBUG) fprintf(stderr, "\tUnable to allocate memory\n");
return 1;
}

dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
NULL, ReplyBuffer, ReplySize, timeout);

int return_code = 0;

if (dwRetVal != 0) {
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
struct in_addr ReplyAddr;
ReplyAddr.S_un.S_addr = pEchoReply->Address;

*latency = pEchoReply->RoundTripTime;
reverse_dns_lookup(info, host);
}
else {
} else {
/* ICMP echo request failed */
return 1;

return_code = 1;;
}
return 0;

free(ReplyBuffer);
return return_code;
}

int send_arp(char *dest, char *dotted) {
Expand All @@ -209,6 +210,10 @@ int send_arp(char *dest, char *dotted) {

dwRetVal = SendARP(DestIp, SrcIp, &MacAddr, &PhysAddrLen);

if (dwRetVal == ERROR_BAD_NET_NAME) {
if (DEBUG) fprintf(stderr, "Error: Cannot send Arp request to a network on different subnet\n");
}

if (dwRetVal == NO_ERROR) {
bPhysAddr = (BYTE *) & MacAddr;
if (PhysAddrLen) {
Expand Down Expand Up @@ -241,7 +246,7 @@ void display_ping_result(char *host, char *result, int latency) {
if (!send_arp(mac, host)) {
fprintf(stdout, "\tMAC: %s", mac);
}
*/
*/
fprintf(stdout, "\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int server(char *port, char *filename, int keep_listening) {

if (keep_listening) {

while (1) {
for (;;) {

ClientSocket = accept(ListenSocket, NULL, NULL);
if (ClientSocket == INVALID_SOCKET) {
Expand Down
3 changes: 2 additions & 1 deletion src/tomcat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TomCat::TomCat(char *filename) {
}

TomCat::~TomCat() {
free(filename);
close_pipes(pipes);
_setmode(fileno(stdout), _O_TEXT);
}
Expand Down Expand Up @@ -81,7 +82,7 @@ int TomCat::Process(SOCKET ClientSocket) {
memset(sendbuf, '\0', DEFAULT_BUFLEN);

/* Main run-forever loop: */
while(1) {
for(;;) {

FD_ZERO(&readfds);
FD_ZERO(&writefds);
Expand Down

0 comments on commit 3af6658

Please sign in to comment.