]> git.kaiwu.me - nginx.git/commitdiff
we can free GeoIPRecord just after GeoIP_region_name_by_code(),
authorIgor Sysoev <igor@sysoev.ru>
Tue, 3 Aug 2010 18:38:08 +0000 (18:38 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 3 Aug 2010 18:38:08 +0000 (18:38 +0000)
because it returns a statically allocated string

src/http/modules/ngx_http_geoip_module.c

index 51e20e7517a9659e1ceb0cd4b3cc95a772ae1323..592314c84658c4ed753383cf533ee9c8c65283fa 100644 (file)
@@ -231,7 +231,6 @@ ngx_http_geoip_city_variable(ngx_http_request_t *r,
 
     len = ngx_strlen(val);
     v->data = ngx_pnalloc(r->pool, len);
-
     if (v->data == NULL) {
         GeoIPRecord_delete(gr);
         return NGX_ERROR;
@@ -274,15 +273,16 @@ ngx_http_geoip_region_name_variable(ngx_http_request_t *r,
     }
 
     val = GeoIP_region_name_by_code(gr->country_code, gr->region);
+
+    GeoIPRecord_delete(gr);
+
     if (val == NULL) {
-        goto no_value;
+        goto not_found;
     }
 
     len = ngx_strlen(val);
     v->data = ngx_pnalloc(r->pool, len);
-
     if (v->data == NULL) {
-        GeoIPRecord_delete(gr);
         return NGX_ERROR;
     }
 
@@ -293,14 +293,8 @@ ngx_http_geoip_region_name_variable(ngx_http_request_t *r,
     v->no_cacheable = 0;
     v->not_found = 0;
 
-    GeoIPRecord_delete(gr);
-
     return NGX_OK;
 
-no_value:
-
-    GeoIPRecord_delete(gr);
-
 not_found:
 
     v->not_found = 1;