libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit d74282806eb98340cea23a4b8db8da3c16f5e3c6
parent 14873b8fa867ac91860cbb85342511a55041611c
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date:   Mon,  2 Sep 2013 21:41:35 +0000

microspdy2http: fixed memory leaks on timedout curl request

Diffstat:
Msrc/spdy2http/proxy.c | 68++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 40 insertions(+), 28 deletions(-)

diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c @@ -455,6 +455,26 @@ response_callback (void *cls, static void +cleanup(struct Proxy *proxy) +{ + int ret; + + //fprintf(stderr, "free proxy for %s\n", proxy->url); + + if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle))) + { + PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret); + } + debug_num_curls--; + curl_slist_free_all(proxy->curl_headers); + curl_easy_cleanup(proxy->curl_handle); + + free(proxy->url); + free(proxy); +} + + +static void response_done_callback(void *cls, struct SPDY_Response *response, struct SPDY_Request *request, @@ -463,7 +483,6 @@ response_done_callback(void *cls, { (void)streamopened; struct Proxy *proxy = (struct Proxy *)cls; - int ret; if(SPDY_RESPONSE_RESULT_SUCCESS != status) { @@ -471,18 +490,9 @@ response_done_callback(void *cls, free(proxy->http_body); proxy->http_body = NULL; } - if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle))) - { - PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret); - } - debug_num_curls--; - curl_slist_free_all(proxy->curl_headers); - curl_easy_cleanup(proxy->curl_handle); - + cleanup(proxy); SPDY_destroy_request(request); SPDY_destroy_response(response); - free(proxy->url); - free(proxy); } @@ -506,6 +516,7 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp) if(!*(proxy->session_alive)) { PRINT_VERBOSE("headers received, but session is dead"); + proxy->error = true; return 0; } @@ -535,10 +546,11 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp) false, &response_done_callback, proxy)) - { + { //DIE("no queue"); //TODO right? proxy->error = true; + PRINT_INFO2("erorr in curl_header_cb for %s", proxy->url); return 0; } @@ -812,6 +824,8 @@ standard_request_handler(void *cls, DIE("No memory"); memset(proxy, 0, sizeof(struct Proxy)); + //fprintf(stderr, "new proxy for %s\n", path); + session = SPDY_get_session_for_request(request); assert(NULL != session); proxy->session_alive = SPDY_get_cls_from_session(session); @@ -1114,6 +1128,9 @@ run () { proxy->done = true; call_spdy_run = true; + //TODO what happens with proxy when the client resets a stream + //and response_done is not yet set for the last frame? is it + //possible? } else { @@ -1121,29 +1138,24 @@ run () if(NULL == proxy->response) { SPDY_name_value_destroy(proxy->headers); - if(!*(proxy->session_alive)) + /*if(!*(proxy->session_alive)) { free(proxy->http_body); proxy->http_body = NULL; - - if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle))) - { - PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret); - } - debug_num_curls--; - curl_slist_free_all(proxy->curl_headers); - curl_easy_cleanup(proxy->curl_handle); - +*/ SPDY_destroy_request(proxy->request); - //SPDY_destroy_response(proxy->response); - free(proxy->url); - free(proxy); - } + cleanup(proxy); + /*} else - proxy->error = true; + proxy->error = true;*/ } else - proxy->error = true; + { + //proxy->error = true; + SPDY_destroy_request(proxy->request); + SPDY_destroy_response(proxy->response); + cleanup(proxy); + } call_spdy_run = true; //TODO spdy should be notified to send RST_STREAM }