From 358b2781af5855e29fb9a37599e1154308117668 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Mon, 22 Oct 2001 16:08:29 +0000 Subject: [PATCH] Cleaned up the code in handle_connection() and added a NULL pointer test in the free request function. --- ChangeLog | 5 +++++ src/reqs.c | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2570a1e..116a4c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2001-10-22 Robert James Kaes + * src/reqs.c (free_request_struct): Added a test to return if the + pointer is NULL. + (handle_connection): Cleaned up the code to better handle the + cause where the request is NULL. + * src/sock.c (getpeer_string): * src/sock.c (getpeer_ip): When the DNS lookup fails, we need to initialized the user's buffer to an empty string; otherwise, the diff --git a/src/reqs.c b/src/reqs.c index 5b4cdbd..2132ea1 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -1,4 +1,4 @@ -/* $Id: reqs.c,v 1.30 2001-10-19 18:03:49 rjkaes Exp $ +/* $Id: reqs.c,v 1.31 2001-10-22 16:08:29 rjkaes Exp $ * * This is where all the work in tinyproxy is actually done. Incoming * connections have a new thread created for them. The thread then @@ -111,6 +111,9 @@ struct request_s { static void free_request_struct(struct request_s *request) { + if (!request) + return; + safefree(request->method); safefree(request->protocol); @@ -836,34 +839,34 @@ internal_proxy: safefree(request_line); if (!request) { - update_stats(STAT_BADCONN); - if (!connptr->send_message) { + update_stats(STAT_BADCONN); destroy_conn(connptr); return; } - } else { -#ifdef UPSTREAM_SUPPORT - if (config.upstream_name && config.upstream_port != -1) { - if (connect_to_upstream(connptr, request) < 0) - goto send_error; - } else { -#endif - connptr->server_fd = opensock(request->host, request->port); - if (connptr->server_fd < 0) { - httperr(connptr, 500, HTTP500ERROR); - goto send_error; - } - - log_message(LOG_CONN, "Established connection to host \"%s\" using file descriptor %d.", request->host, connptr->server_fd); - - if (!connptr->ssl) - establish_http_connection(connptr, request); -#ifdef UPSTREAM_SUPPORT - } -#endif + goto send_error; } +#ifdef UPSTREAM_SUPPORT + if (config.upstream_name && config.upstream_port != -1) { + if (connect_to_upstream(connptr, request) < 0) + goto send_error; + } else { +#endif + connptr->server_fd = opensock(request->host, request->port); + if (connptr->server_fd < 0) { + httperr(connptr, 500, HTTP500ERROR); + goto send_error; + } + + log_message(LOG_CONN, "Established connection to host \"%s\" using file descriptor %d.", request->host, connptr->server_fd); + + if (!connptr->ssl) + establish_http_connection(connptr, request); +#ifdef UPSTREAM_SUPPORT + } +#endif + send_error: free_request_struct(request);