aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-08-19 17:44:33 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-08-19 17:44:33 +0000
commit0f00b0a801008c2d2185285049b79a0a2fc01b49 (patch)
tree07cea8c3d8304bbfbbc4435a831c59e12166b55f /src
parent42e49ba1ef313749f2ffd58631201f7d5ce5eb14 (diff)
downloadnginx-0f00b0a801008c2d2185285049b79a0a2fc01b49.tar.gz
nginx-0f00b0a801008c2d2185285049b79a0a2fc01b49.zip
fix memory leak if GeoIP City database was used
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_geoip_module.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c
index 2d3fe20f2..81b872efb 100644
--- a/src/http/modules/ngx_http_geoip_module.c
+++ b/src/http/modules/ngx_http_geoip_module.c
@@ -181,6 +181,7 @@ ngx_http_geoip_city_variable(ngx_http_request_t *r,
{
u_long addr;
char *val;
+ size_t len;
GeoIPRecord *gr;
struct sockaddr_in *sin;
ngx_http_geoip_conf_t *gcf;
@@ -207,17 +208,32 @@ ngx_http_geoip_city_variable(ngx_http_request_t *r,
val = *(char **) ((char *) gr + data);
if (val == NULL) {
- goto not_found;
+ goto no_value;
}
- v->len = ngx_strlen(val);
+ len = ngx_strlen(val);
+ v->data = ngx_pnalloc(r->pool, len);
+
+ if (v->data == NULL) {
+ GeoIPRecord_delete(gr);
+ 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;
+
+ GeoIPRecord_delete(gr);
return NGX_OK;
+no_value:
+
+ GeoIPRecord_delete(gr);
+
not_found:
v->not_found = 1;