Mercurial > hg > nginx
comparison src/http/modules/ngx_http_geoip_module.c @ 3031:98a8336c5b7c
fix memory leak if GeoIP City database was used
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 19 Aug 2009 17:44:33 +0000 |
parents | 31af2d1a742e |
children | 236634d2b603 |
comparison
equal
deleted
inserted
replaced
3030:3e507aa47097 | 3031:98a8336c5b7c |
---|---|
179 ngx_http_geoip_city_variable(ngx_http_request_t *r, | 179 ngx_http_geoip_city_variable(ngx_http_request_t *r, |
180 ngx_http_variable_value_t *v, uintptr_t data) | 180 ngx_http_variable_value_t *v, uintptr_t data) |
181 { | 181 { |
182 u_long addr; | 182 u_long addr; |
183 char *val; | 183 char *val; |
184 size_t len; | |
184 GeoIPRecord *gr; | 185 GeoIPRecord *gr; |
185 struct sockaddr_in *sin; | 186 struct sockaddr_in *sin; |
186 ngx_http_geoip_conf_t *gcf; | 187 ngx_http_geoip_conf_t *gcf; |
187 | 188 |
188 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module); | 189 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module); |
205 } | 206 } |
206 | 207 |
207 val = *(char **) ((char *) gr + data); | 208 val = *(char **) ((char *) gr + data); |
208 | 209 |
209 if (val == NULL) { | 210 if (val == NULL) { |
210 goto not_found; | 211 goto no_value; |
211 } | 212 } |
212 | 213 |
213 v->len = ngx_strlen(val); | 214 len = ngx_strlen(val); |
215 v->data = ngx_pnalloc(r->pool, len); | |
216 | |
217 if (v->data == NULL) { | |
218 GeoIPRecord_delete(gr); | |
219 return NGX_ERROR; | |
220 } | |
221 | |
222 ngx_memcpy(v->data, val, len); | |
223 | |
224 v->len = len; | |
214 v->valid = 1; | 225 v->valid = 1; |
215 v->no_cacheable = 0; | 226 v->no_cacheable = 0; |
216 v->not_found = 0; | 227 v->not_found = 0; |
217 v->data = (u_char *) val; | 228 |
218 | 229 GeoIPRecord_delete(gr); |
219 return NGX_OK; | 230 |
231 return NGX_OK; | |
232 | |
233 no_value: | |
234 | |
235 GeoIPRecord_delete(gr); | |
220 | 236 |
221 not_found: | 237 not_found: |
222 | 238 |
223 v->not_found = 1; | 239 v->not_found = 1; |
224 | 240 |