Mercurial > hg > nginx
comparison src/http/modules/ngx_http_geoip_module.c @ 4718:a05e7b09af5a stable-1.2
Merge of r4648, r4649, r4650: memory leak with $geoip_org.
Patch by Denis F. Latypoff (slightly modified).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 02 Jul 2012 15:41:31 +0000 |
parents | ba2c7463ce18 |
children | 880dedfa4008 |
comparison
equal
deleted
inserted
replaced
4717:bd45a98ff226 | 4718:a05e7b09af5a |
---|---|
26 ngx_str_t *name; | 26 ngx_str_t *name; |
27 uintptr_t data; | 27 uintptr_t data; |
28 } ngx_http_geoip_var_t; | 28 } ngx_http_geoip_var_t; |
29 | 29 |
30 | 30 |
31 typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr); | 31 typedef char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr); |
32 | 32 |
33 static u_long ngx_http_geoip_addr(ngx_http_request_t *r, | 33 static u_long ngx_http_geoip_addr(ngx_http_request_t *r, |
34 ngx_http_geoip_conf_t *gcf); | 34 ngx_http_geoip_conf_t *gcf); |
35 static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r, | 35 static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r, |
36 ngx_http_variable_value_t *v, uintptr_t data); | 36 ngx_http_variable_value_t *v, uintptr_t data); |
289 ngx_http_variable_value_t *v, uintptr_t data) | 289 ngx_http_variable_value_t *v, uintptr_t data) |
290 { | 290 { |
291 ngx_http_geoip_variable_handler_pt handler = | 291 ngx_http_geoip_variable_handler_pt handler = |
292 (ngx_http_geoip_variable_handler_pt) data; | 292 (ngx_http_geoip_variable_handler_pt) data; |
293 | 293 |
294 const char *val; | 294 size_t len; |
295 char *val; | |
295 ngx_http_geoip_conf_t *gcf; | 296 ngx_http_geoip_conf_t *gcf; |
296 | 297 |
297 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module); | 298 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module); |
298 | 299 |
299 if (gcf->org == NULL) { | 300 if (gcf->org == NULL) { |
304 | 305 |
305 if (val == NULL) { | 306 if (val == NULL) { |
306 goto not_found; | 307 goto not_found; |
307 } | 308 } |
308 | 309 |
309 v->len = ngx_strlen(val); | 310 len = ngx_strlen(val); |
311 v->data = ngx_pnalloc(r->pool, len); | |
312 if (v->data == NULL) { | |
313 ngx_free(val); | |
314 return NGX_ERROR; | |
315 } | |
316 | |
317 ngx_memcpy(v->data, val, len); | |
318 | |
319 v->len = len; | |
310 v->valid = 1; | 320 v->valid = 1; |
311 v->no_cacheable = 0; | 321 v->no_cacheable = 0; |
312 v->not_found = 0; | 322 v->not_found = 0; |
313 v->data = (u_char *) val; | 323 |
324 ngx_free(val); | |
314 | 325 |
315 return NGX_OK; | 326 return NGX_OK; |
316 | 327 |
317 not_found: | 328 not_found: |
318 | 329 |