Skip to content

Commit

Permalink
Cleans up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nnposter committed Jan 21, 2019
1 parent aac899b commit 735abe6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ncat/ncat_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ static int do_proxy_http(void)
request = http_connect_request(o.target,o.portno, &n);
if (send(sd, request, n, 0) < 0) {
loguser("Error sending proxy request: %s.\n", socket_strerror(socket_errno()));
free(request);
return -1;
goto bail;
}
free(request);
request = NULL;

socket_buffer_init(&sockbuf, sd);

Expand Down Expand Up @@ -510,11 +510,11 @@ static int do_proxy_http(void)
logdebug("Reconnection header:\n%s", request);
if (send(sd, request, n, 0) < 0) {
loguser("Error sending proxy request: %s.\n", socket_strerror(socket_errno()));
free(request);
http_challenge_free(&challenge);
goto bail;
}
free(request);
request = NULL;
http_challenge_free(&challenge);

socket_buffer_init(&sockbuf, sd);
Expand All @@ -534,14 +534,14 @@ static int do_proxy_http(void)
}
}

free(header);
header = NULL;

if (code != 200) {
loguser("Proxy returned status code %d.\n", code);
return -1;
goto bail;
}

free(header);
header = NULL;

remainder = socket_buffer_remainder(&sockbuf, &len);
Write(STDOUT_FILENO, remainder, len);

Expand All @@ -550,6 +550,8 @@ static int do_proxy_http(void)
bail:
if (sd != -1)
close(sd);
if (request != NULL)
free(request);
if (status_line != NULL)
free(status_line);
if (header != NULL)
Expand Down

0 comments on commit 735abe6

Please sign in to comment.