Previously, njs_vm_clone() copied the call stack pointers of the VM
being cloned. A VM created with the "init" option keeps its initial
frame, so every clone allocated frames in the spare space of that
frame instead of its own memory. When two clones of the same VM ran at
the same time, they overwrote each other's frames. In nginx, this
happened when a parent handler evaluated a js_set variable of a
subrequest: the subrequest clone overwrote the frames of the running
parent clone, which crashed after returning from the native call.
Now a cloned VM starts with an empty call stack and allocates its own
initial frame.
The issue was introduced in
16f42c87 (0.8.8).
nvm->trace.data = nvm;
nvm->external = external;
+ nvm->active_frame = NULL;
+ nvm->top_frame = NULL;
+
nvm->shared_atom_count = vm->atom_id_generator;
njs_flathsh_init(&nvm->atom_hash);