aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Uzunov <andrey.uzunov@gmail.com>2013-09-02 21:41:35 +0000
committerAndrey Uzunov <andrey.uzunov@gmail.com>2013-09-02 21:41:35 +0000
commitd74282806eb98340cea23a4b8db8da3c16f5e3c6 (patch)
tree92087561a9aa5ae7e93580e9bdf34faa3d19f777
parent14873b8fa867ac91860cbb85342511a55041611c (diff)
downloadlibmicrohttpd-d74282806eb98340cea23a4b8db8da3c16f5e3c6.tar.gz
libmicrohttpd-d74282806eb98340cea23a4b8db8da3c16f5e3c6.zip
microspdy2http: fixed memory leaks on timedout curl request
-rw-r--r--src/spdy2http/proxy.c68
1 files changed, 40 insertions, 28 deletions
diff --git a/src/spdy2http/proxy.c b/src/spdy2http/proxy.c
index 46b25255..0623e23d 100644
--- a/src/spdy2http/proxy.c
+++ b/src/spdy2http/proxy.c
@@ -455,6 +455,26 @@ response_callback (void *cls,
455 455
456 456
457static void 457static void
458cleanup(struct Proxy *proxy)
459{
460 int ret;
461
462 //fprintf(stderr, "free proxy for %s\n", proxy->url);
463
464 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle)))
465 {
466 PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret);
467 }
468 debug_num_curls--;
469 curl_slist_free_all(proxy->curl_headers);
470 curl_easy_cleanup(proxy->curl_handle);
471
472 free(proxy->url);
473 free(proxy);
474}
475
476
477static void
458response_done_callback(void *cls, 478response_done_callback(void *cls,
459 struct SPDY_Response *response, 479 struct SPDY_Response *response,
460 struct SPDY_Request *request, 480 struct SPDY_Request *request,
@@ -463,7 +483,6 @@ response_done_callback(void *cls,
463{ 483{
464 (void)streamopened; 484 (void)streamopened;
465 struct Proxy *proxy = (struct Proxy *)cls; 485 struct Proxy *proxy = (struct Proxy *)cls;
466 int ret;
467 486
468 if(SPDY_RESPONSE_RESULT_SUCCESS != status) 487 if(SPDY_RESPONSE_RESULT_SUCCESS != status)
469 { 488 {
@@ -471,18 +490,9 @@ response_done_callback(void *cls,
471 free(proxy->http_body); 490 free(proxy->http_body);
472 proxy->http_body = NULL; 491 proxy->http_body = NULL;
473 } 492 }
474 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle))) 493 cleanup(proxy);
475 {
476 PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret);
477 }
478 debug_num_curls--;
479 curl_slist_free_all(proxy->curl_headers);
480 curl_easy_cleanup(proxy->curl_handle);
481
482 SPDY_destroy_request(request); 494 SPDY_destroy_request(request);
483 SPDY_destroy_response(response); 495 SPDY_destroy_response(response);
484 free(proxy->url);
485 free(proxy);
486} 496}
487 497
488 498
@@ -506,6 +516,7 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
506 if(!*(proxy->session_alive)) 516 if(!*(proxy->session_alive))
507 { 517 {
508 PRINT_VERBOSE("headers received, but session is dead"); 518 PRINT_VERBOSE("headers received, but session is dead");
519 proxy->error = true;
509 return 0; 520 return 0;
510 } 521 }
511 522
@@ -535,10 +546,11 @@ curl_header_cb(void *ptr, size_t size, size_t nmemb, void *userp)
535 false, 546 false,
536 &response_done_callback, 547 &response_done_callback,
537 proxy)) 548 proxy))
538 { 549 {
539 //DIE("no queue"); 550 //DIE("no queue");
540 //TODO right? 551 //TODO right?
541 proxy->error = true; 552 proxy->error = true;
553 PRINT_INFO2("erorr in curl_header_cb for %s", proxy->url);
542 return 0; 554 return 0;
543 } 555 }
544 556
@@ -812,6 +824,8 @@ standard_request_handler(void *cls,
812 DIE("No memory"); 824 DIE("No memory");
813 memset(proxy, 0, sizeof(struct Proxy)); 825 memset(proxy, 0, sizeof(struct Proxy));
814 826
827 //fprintf(stderr, "new proxy for %s\n", path);
828
815 session = SPDY_get_session_for_request(request); 829 session = SPDY_get_session_for_request(request);
816 assert(NULL != session); 830 assert(NULL != session);
817 proxy->session_alive = SPDY_get_cls_from_session(session); 831 proxy->session_alive = SPDY_get_cls_from_session(session);
@@ -1114,6 +1128,9 @@ run ()
1114 { 1128 {
1115 proxy->done = true; 1129 proxy->done = true;
1116 call_spdy_run = true; 1130 call_spdy_run = true;
1131 //TODO what happens with proxy when the client resets a stream
1132 //and response_done is not yet set for the last frame? is it
1133 //possible?
1117 } 1134 }
1118 else 1135 else
1119 { 1136 {
@@ -1121,29 +1138,24 @@ run ()
1121 if(NULL == proxy->response) 1138 if(NULL == proxy->response)
1122 { 1139 {
1123 SPDY_name_value_destroy(proxy->headers); 1140 SPDY_name_value_destroy(proxy->headers);
1124 if(!*(proxy->session_alive)) 1141 /*if(!*(proxy->session_alive))
1125 { 1142 {
1126 free(proxy->http_body); 1143 free(proxy->http_body);
1127 proxy->http_body = NULL; 1144 proxy->http_body = NULL;
1128 1145*/
1129 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle)))
1130 {
1131 PRINT_INFO2("curl_multi_remove_handle failed (%i)", ret);
1132 }
1133 debug_num_curls--;
1134 curl_slist_free_all(proxy->curl_headers);
1135 curl_easy_cleanup(proxy->curl_handle);
1136
1137 SPDY_destroy_request(proxy->request); 1146 SPDY_destroy_request(proxy->request);
1138 //SPDY_destroy_response(proxy->response); 1147 cleanup(proxy);
1139 free(proxy->url); 1148 /*}
1140 free(proxy);
1141 }
1142 else 1149 else
1143 proxy->error = true; 1150 proxy->error = true;*/
1144 } 1151 }
1145 else 1152 else
1146 proxy->error = true; 1153 {
1154 //proxy->error = true;
1155 SPDY_destroy_request(proxy->request);
1156 SPDY_destroy_response(proxy->response);
1157 cleanup(proxy);
1158 }
1147 call_spdy_run = true; 1159 call_spdy_run = true;
1148 //TODO spdy should be notified to send RST_STREAM 1160 //TODO spdy should be notified to send RST_STREAM
1149 } 1161 }