[njs] Fixed external_objects cloning.

Dmitry Volyntsev xeioex at nginx.com
Fri Mar 23 11:22:23 UTC 2018


details:   http://hg.nginx.org/njs/rev/567cdbcee5ce
branches:  
changeset: 469:567cdbcee5ce
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Mar 23 14:02:22 2018 +0300
description:
Fixed external_objects cloning.

diffstat:

 njs/njscript.c |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (39 lines):

diff -r 77e675beae48 -r 567cdbcee5ce njs/njscript.c
--- a/njs/njscript.c	Fri Mar 23 13:53:27 2018 +0300
+++ b/njs/njscript.c	Fri Mar 23 14:02:22 2018 +0300
@@ -323,6 +323,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_
     njs_vm_t              *nvm;
     uint32_t              items;
     nxt_int_t             ret;
+    nxt_array_t           *externals;
     nxt_mem_cache_pool_t  *nmcp;
 
     nxt_thread_log_debug("CLONE:");
@@ -352,19 +353,21 @@ njs_vm_clone(njs_vm_t *vm, njs_external_
         nvm->external_prototypes_hash = vm->external_prototypes_hash;
 
         items = vm->external_objects->items;
-        nvm->external_objects = nxt_array_create(items + 4, sizeof(void *),
-                                                 &njs_array_mem_proto,
-                                                 vm->mem_cache_pool);
-        if (nxt_slow_path(vm->external_objects == NULL)) {
+        externals = nxt_array_create(items + 4, sizeof(void *),
+                                     &njs_array_mem_proto, nvm->mem_cache_pool);
+
+        if (nxt_slow_path(externals == NULL)) {
             return NULL;
         }
 
         if (items > 0) {
-            memcpy(nvm->external_objects->start, vm->external_objects->start,
+            memcpy(externals->start, vm->external_objects->start,
                    items * sizeof(void *));
-            vm->external_objects->items = items;
+            externals->items = items;
         }
 
+        nvm->external_objects = externals;
+
         nvm->ops = vm->ops;
 
         nvm->current = vm->current;


More information about the nginx-devel mailing list