@@ -53,29 +53,34 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
5353 ngx_int_t address_status = ngx_http_bot_verifier_module_determine_address (r , address );
5454 if (address_status == NGX_ERROR ) {
5555 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Unable to determine connected address, bypassing" );
56+ free (address );
5657 return NGX_DECLINED ;
5758 }
5859
5960 ngx_int_t verification_status = lookup_verification_status (loc_conf -> redis .connection , address );
6061 if (verification_status == NGX_ERROR ) {
6162 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Unable to lookup verification status, bypassing" );
63+ free (address );
6264 return NGX_DECLINED ;
6365 }
6466
6567 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Lookup result %d" , verification_status );
6668
6769 if (verification_status == SUCCESS ) {
6870 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Actor has already been verified, bypassing" );
71+ free (address );
6972 return NGX_DECLINED ;
7073 }
7174
7275 if (verification_status == FAILURE ) {
7376 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Actor previously failed verification, blocking request" );
77+ free (address );
7478 return NGX_HTTP_FORBIDDEN ;
7579 }
7680
7781 if (verification_status == ERROR ) {
7882 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "There was an error looking up the actor, failing open" );
83+ free (address );
7984 return NGX_DECLINED ;
8085 }
8186
@@ -94,12 +99,14 @@ ngx_http_bot_verifier_module_handler(ngx_http_request_t *r)
9499 } else if (ret == NGX_DECLINED ) {
95100 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Verification failed" );
96101 persist_verification_status (loc_conf -> redis .connection , address , ret , loc_conf -> redis .expiry );
102+ free (address );
97103 return NGX_HTTP_FORBIDDEN ;
98104 }
99105 } else {
100106 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "Bot does not identify" );
101107 }
102108
109+ free (address );
103110 return NGX_OK ;
104111}
105112
@@ -206,8 +213,7 @@ ngx_http_bot_verifier_module_create_loc_conf(ngx_conf_t *cf)
206213 provider_t * yahoo = make_provider ("Yahoo" , yahoo_domains , len );
207214
208215 conf -> provider_len = 3 ;
209- // TODO: use nginx allocation
210- conf -> providers = malloc (sizeof (provider_t * * ) + conf -> provider_len * sizeof (provider_t * ));
216+ conf -> providers = ngx_pcalloc (cf -> pool , sizeof (provider_t * * ) + conf -> provider_len * sizeof (provider_t * ));
211217 conf -> providers [0 ] = google ;
212218 conf -> providers [1 ] = yahoo ;
213219 conf -> providers [2 ] = bing ;
0 commit comments