comparison src/http/modules/ngx_http_geoip_module.c @ 3742:01691af60f94

we can free GeoIPRecord just after GeoIP_region_name_by_code(), because it returns a statically allocated string
author Igor Sysoev <igor@sysoev.ru>
date Tue, 03 Aug 2010 18:38:08 +0000
parents 0f9b2d285bfc
children 30d4d6187316
comparison
equal deleted inserted replaced
3741:0f9b2d285bfc 3742:01691af60f94
229 goto no_value; 229 goto no_value;
230 } 230 }
231 231
232 len = ngx_strlen(val); 232 len = ngx_strlen(val);
233 v->data = ngx_pnalloc(r->pool, len); 233 v->data = ngx_pnalloc(r->pool, len);
234
235 if (v->data == NULL) { 234 if (v->data == NULL) {
236 GeoIPRecord_delete(gr); 235 GeoIPRecord_delete(gr);
237 return NGX_ERROR; 236 return NGX_ERROR;
238 } 237 }
239 238
272 if (gr == NULL) { 271 if (gr == NULL) {
273 goto not_found; 272 goto not_found;
274 } 273 }
275 274
276 val = GeoIP_region_name_by_code(gr->country_code, gr->region); 275 val = GeoIP_region_name_by_code(gr->country_code, gr->region);
276
277 GeoIPRecord_delete(gr);
278
277 if (val == NULL) { 279 if (val == NULL) {
278 goto no_value; 280 goto not_found;
279 } 281 }
280 282
281 len = ngx_strlen(val); 283 len = ngx_strlen(val);
282 v->data = ngx_pnalloc(r->pool, len); 284 v->data = ngx_pnalloc(r->pool, len);
283
284 if (v->data == NULL) { 285 if (v->data == NULL) {
285 GeoIPRecord_delete(gr);
286 return NGX_ERROR; 286 return NGX_ERROR;
287 } 287 }
288 288
289 ngx_memcpy(v->data, val, len); 289 ngx_memcpy(v->data, val, len);
290 290
291 v->len = len; 291 v->len = len;
292 v->valid = 1; 292 v->valid = 1;
293 v->no_cacheable = 0; 293 v->no_cacheable = 0;
294 v->not_found = 0; 294 v->not_found = 0;
295 295
296 GeoIPRecord_delete(gr); 296 return NGX_OK;
297
298 return NGX_OK;
299
300 no_value:
301
302 GeoIPRecord_delete(gr);
303 297
304 not_found: 298 not_found:
305 299
306 v->not_found = 1; 300 v->not_found = 1;
307 301