]> git.kaiwu.me - nginx.git/commitdiff
Map: fixed optimization of variables as values.
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 16 Aug 2012 10:58:18 +0000 (10:58 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 16 Aug 2012 10:58:18 +0000 (10:58 +0000)
Previous code incorrectly used ctx->var_values as an array of pointers to
ngx_http_variable_value_t, but the array contains structures, not pointers.
Additionally, ctx->var_values inspection failed to properly set var on
match.

src/http/modules/ngx_http_map_module.c

index e8a4ab4cc18b61e6c276b0224bc0408f31fbf2bc..54f9ec4459bbdf084fa575e991d8757ec5e858bd 100644 (file)
@@ -416,11 +416,12 @@ ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
 
         for (i = 0; i < ctx->var_values.nelts; i++) {
             if (index == (ngx_int_t) var[i].data) {
+                var = &var[i];
                 goto found;
             }
         }
 
-        var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t));
+        var = ngx_array_push(&ctx->var_values);
         if (var == NULL) {
             return NGX_CONF_ERROR;
         }
@@ -431,13 +432,6 @@ ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
         var->len = 0;
         var->data = (u_char *) index;
 
-        vp = ngx_array_push(&ctx->var_values);
-        if (vp == NULL) {
-            return NGX_CONF_ERROR;
-        }
-
-        *vp = var;
-
         goto found;
     }