@@ -31,6 +31,7 @@ static char *ngx_http_ip2proxy_database(ngx_conf_t *cf, ngx_command_t *cmd, void
3131static char * ngx_http_ip2proxy_proxy (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
3232static ngx_int_t ngx_http_ip2proxy_cidr_value (ngx_conf_t * cf , ngx_str_t * net , ngx_cidr_t * cidr );
3333static void ngx_http_ip2proxy_cleanup (void * data );
34+ static IP2Proxy * ip2proxy_bin_handler ;
3435
3536static ngx_command_t ngx_http_ip2proxy_commands [] = {
3637 {
@@ -345,6 +346,12 @@ ngx_http_ip2proxy_database(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
345346 return "Duplicated" ;
346347 }
347348
349+ if (ip2proxy_bin_handler ){
350+ //close the bin if it's still opened
351+ IP2Proxy_close (ip2proxy_bin_handler );
352+ ip2proxy_bin_handler = NULL ;
353+ }
354+
348355 value = cf -> args -> elts ;
349356
350357 if (value [1 ].len == 0 ) {
@@ -354,6 +361,7 @@ ngx_http_ip2proxy_database(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
354361
355362 // Open IP2Proxy BIN database
356363 gcf -> handler = IP2Proxy_open ((char * ) value [1 ].data );
364+ ip2proxy_bin_handler = gcf -> handler ;
357365
358366 if (gcf -> handler == NULL ) {
359367 ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "Unable to open database file \"%s\"." , & value [1 ].data );
@@ -426,10 +434,10 @@ ngx_http_ip2proxy_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr)
426434static void
427435ngx_http_ip2proxy_cleanup (void * data )
428436{
429- ngx_http_ip2proxy_conf_t * gcf = data ;
437+ // ngx_http_ip2proxy_conf_t *gcf = data;
430438
431- if (gcf -> handler ) {
432- IP2Proxy_close (gcf -> handler );
433- gcf -> handler = NULL ;
434- }
439+ // if (gcf->handler) {
440+ // IP2Proxy_close(gcf->handler);
441+ // gcf->handler = NULL;
442+ // }
435443}
0 commit comments