diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 053c23c20..75a28735d 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -557,11 +557,17 @@ ngx_engine_njs_init(ngx_engine_t *engine, ngx_engine_opts_t *opts) vm_options.backtrace = 1; vm_options.addons = opts->u.njs.addons; vm_options.metas = opts->u.njs.metas; - vm_options.file = opts->file; vm_options.argv = ngx_argv; vm_options.argc = ngx_argc; vm_options.init = 1; + vm_options.file.start = njs_mp_alloc(engine->pool, opts->file.length); + if (vm_options.file.start == NULL) { + return NGX_ERROR; + } + + ngx_memcpy(vm_options.file.start, opts->file.start, opts->file.length); + vm = njs_vm_create(&vm_options); if (vm == NULL) { return NGX_ERROR; @@ -571,6 +577,7 @@ ngx_engine_njs_init(ngx_engine_t *engine, ngx_engine_opts_t *opts) rc = ngx_js_set_cwd(njs_vm_memory_pool(vm), opts->conf, &vm_options.file); if (rc != NGX_OK) { + njs_vm_destroy(vm); return NGX_ERROR; } @@ -578,7 +585,7 @@ ngx_engine_njs_init(ngx_engine_t *engine, ngx_engine_opts_t *opts) engine->u.njs.vm = vm; - return NJS_OK; + return NGX_OK; } @@ -665,6 +672,7 @@ ngx_njs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, void *external) engine = njs_mp_alloc(njs_vm_memory_pool(vm), sizeof(ngx_engine_t)); if (engine == NULL) { + njs_vm_destroy(vm); return NULL; } @@ -677,6 +685,8 @@ ngx_njs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, void *external) ngx_log_error(NGX_LOG_ERR, ctx->log, 0, "js exception: %V", &exception); + njs_vm_destroy(vm); + return NULL; } diff --git a/nginx/t/js_import2.t b/nginx/t/js_import2.t index 7fdc624d9..c3b4050e7 100644 --- a/nginx/t/js_import2.t +++ b/nginx/t/js_import2.t @@ -64,6 +64,11 @@ http { js_content fun; } + location /test_exception { + js_import exception.js; + js_content exception.nonexistent; + } + location /test_var { return 200 $test; } @@ -105,6 +110,11 @@ $t->write_file('fun.js', <write_file('exception.js', <write_file('main.js', <stop(); my $content = $t->read_file('error.log'); my $count = () = $content =~ m/js vm init/g; -ok($count == 4, 'uniq js vm contexts'); +ok($count == 5, 'uniq js vm contexts'); ############################################################################### diff --git a/src/njs.h b/src/njs.h index 702e74b5a..923cb3e4c 100644 --- a/src/njs.h +++ b/src/njs.h @@ -11,8 +11,8 @@ #include -#define NJS_VERSION "0.9.2" -#define NJS_VERSION_NUMBER 0x000902 +#define NJS_VERSION "0.9.3" +#define NJS_VERSION_NUMBER 0x000903 #include diff --git a/src/njs_vm.c b/src/njs_vm.c index 19c50e48f..4b4a881a2 100644 --- a/src/njs_vm.c +++ b/src/njs_vm.c @@ -327,7 +327,7 @@ njs_vm_compile_module(njs_vm_t *vm, njs_str_t *name, u_char **start, return NULL; } - ret = njs_parser_init(vm, &parser, NULL, name, *start, end); + ret = njs_parser_init(vm, &parser, NULL, &module->name, *start, end); if (njs_slow_path(ret != NJS_OK)) { return NULL; }