[nginx] svn commit: r4719 - in branches/stable-1.2: . src/http/modules

mdounin at mdounin.ru mdounin at mdounin.ru
Mon Jul 2 15:41:32 UTC 2012


Author: mdounin
Date: 2012-07-02 15:41:31 +0000 (Mon, 02 Jul 2012)
New Revision: 4719
URL: http://trac.nginx.org/nginx/changeset/4719/nginx

Log:
Merge of r4648, r4649, r4650: memory leak with $geoip_org.

Patch by Denis F. Latypoff (slightly modified).


Modified:
   branches/stable-1.2/
   branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c

Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2	2012-07-02 15:39:28 UTC (rev 4718)
+++ branches/stable-1.2	2012-07-02 15:41:31 UTC (rev 4719)

Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4647,4674-4676
+/trunk:4611-4632,4636-4650,4674-4676
\ No newline at end of property
Modified: branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c
===================================================================
--- branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c	2012-07-02 15:39:28 UTC (rev 4718)
+++ branches/stable-1.2/src/http/modules/ngx_http_geoip_module.c	2012-07-02 15:41:31 UTC (rev 4719)
@@ -28,7 +28,7 @@
 } ngx_http_geoip_var_t;
 
 
-typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
+typedef char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
 
 static u_long ngx_http_geoip_addr(ngx_http_request_t *r,
     ngx_http_geoip_conf_t *gcf);
@@ -291,7 +291,8 @@
     ngx_http_geoip_variable_handler_pt  handler =
         (ngx_http_geoip_variable_handler_pt) data;
 
-    const char             *val;
+    size_t                  len;
+    char                   *val;
     ngx_http_geoip_conf_t  *gcf;
 
     gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module);
@@ -306,12 +307,22 @@
         goto not_found;
     }
 
-    v->len = ngx_strlen(val);
+    len = ngx_strlen(val);
+    v->data = ngx_pnalloc(r->pool, len);
+    if (v->data == NULL) {
+        ngx_free(val);
+        return NGX_ERROR;
+    }
+
+    ngx_memcpy(v->data, val, len);
+
+    v->len = len;
     v->valid = 1;
     v->no_cacheable = 0;
     v->not_found = 0;
-    v->data = (u_char *) val;
 
+    ngx_free(val);
+
     return NGX_OK;
 
 not_found:



More information about the nginx-devel mailing list