@@ -21,12 +21,6 @@ static apr_status_t redirectionio_read_string(redirectionio_connection *conn, ch
2121
2222static apr_status_t redirectionio_send_protocol_header (redirectionio_connection * conn , const char * project_key , apr_uint16_t command , request_rec * r );
2323
24- static apr_status_t redirectionio_action_cleanup (void * action );
25-
26- static apr_status_t redirectionio_request_cleanup (void * request );
27-
28- static apr_status_t redirectionio_response_headers_cleanup (void * response_headers );
29-
3024apr_status_t redirectionio_protocol_match (redirectionio_connection * conn , redirectionio_context * ctx , request_rec * r , const char * project_key ) {
3125 apr_uint32_t alen ;
3226 apr_status_t rv ;
@@ -92,8 +86,6 @@ apr_status_t redirectionio_protocol_match(redirectionio_connection *conn, redire
9286
9387 redirectionio_request_set_remote_addr (ctx -> request , r -> connection -> client_ip , config -> trusted_proxies );
9488
95- apr_pool_pre_cleanup_register (r -> pool , ctx -> request , redirectionio_request_cleanup );
96-
9789 // Serialize request
9890 request_serialized = redirectionio_request_json_serialize (ctx -> request );
9991
@@ -155,10 +147,6 @@ apr_status_t redirectionio_protocol_match(redirectionio_connection *conn, redire
155147
156148 // Unserialize action
157149 ctx -> action = (struct REDIRECTIONIO_Action * )redirectionio_action_json_deserialize (action_serialized );
158-
159- if (ctx -> action != NULL ) {
160- apr_pool_pre_cleanup_register (r -> pool , ctx -> action , redirectionio_action_cleanup );
161- }
162150 }
163151
164152 return APR_SUCCESS ;
@@ -259,7 +247,6 @@ apr_status_t redirectionio_protocol_send_filter_headers(redirectionio_context *c
259247 return APR_SUCCESS ;
260248 }
261249
262- apr_pool_pre_cleanup_register (r -> pool , ctx -> response_headers , redirectionio_response_headers_cleanup );
263250 apr_table_clear (r -> headers_out );
264251
265252 while (first_header != NULL ) {
@@ -448,31 +435,38 @@ static apr_status_t redirectionio_send_protocol_header(redirectionio_connection
448435 return APR_SUCCESS ;
449436}
450437
451- static apr_status_t redirectionio_action_cleanup (void * action ) {
452- redirectionio_action_drop (action );
438+ apr_status_t redirectionio_context_cleanup (void * context ) {
439+ struct REDIRECTIONIO_HeaderMap * first_header , * tmp_header ;
440+ redirectionio_context * ctx = (redirectionio_context * )context ;
453441
454- return APR_SUCCESS ;
455- }
442+ if (ctx -> request != NULL ) {
443+ redirectionio_request_drop (ctx -> request );
444+ }
456445
457- static apr_status_t redirectionio_request_cleanup (void * request ) {
458- redirectionio_request_drop (request );
446+ if (ctx -> action != NULL ) {
447+ redirectionio_action_drop (ctx -> action );
448+ ctx -> action = NULL ;
449+ }
459450
460- return APR_SUCCESS ;
461- }
451+ if ( ctx -> response_headers != NULL ) {
452+ first_header = ( struct REDIRECTIONIO_HeaderMap * ) ctx -> response_headers ;
462453
463- static apr_status_t redirectionio_response_headers_cleanup ( void * response_headers ) {
464- struct REDIRECTIONIO_HeaderMap * first_header , * tmp_header ;
454+ while ( first_header != NULL ) {
455+ tmp_header = first_header -> next ;
465456
466- first_header = (struct REDIRECTIONIO_HeaderMap * )response_headers ;
457+ free ((void * )first_header -> name );
458+ free ((void * )first_header -> value );
459+ free ((void * )first_header );
467460
468- while ( first_header != NULL ) {
469- tmp_header = first_header -> next ;
461+ first_header = tmp_header ;
462+ }
470463
471- free ((void * )first_header -> name );
472- free ((void * )first_header -> value );
473- free ((void * )first_header );
464+ ctx -> response_headers = NULL ;
465+ }
474466
475- first_header = tmp_header ;
467+ if (ctx -> body_filter != NULL ) {
468+ redirectionio_action_body_filter_drop (ctx -> body_filter );
469+ ctx -> body_filter = NULL ;
476470 }
477471
478472 return APR_SUCCESS ;
0 commit comments