[njs] Shell: fixed memory pool issues introduced in cb3e068a511c.

Dmitry Volyntsev xeioex at nginx.com
Thu Feb 29 17:00:33 UTC 2024


details:   https://hg.nginx.org/njs/rev/46699330f4f2
branches:  
changeset: 2292:46699330f4f2
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Feb 27 23:25:05 2024 -0800
description:
Shell: fixed memory pool issues introduced in cb3e068a511c.

diffstat:

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

diffs (52 lines):

diff -r e73d4947372d -r 46699330f4f2 external/njs_shell.c
--- a/external/njs_shell.c	Tue Feb 27 23:24:55 2024 -0800
+++ b/external/njs_shell.c	Tue Feb 27 23:25:05 2024 -0800
@@ -1270,7 +1270,7 @@ njs_module_loader(njs_vm_t *vm, njs_exte
         return NULL;
     }
 
-    ret = njs_module_read(njs_vm_memory_pool(vm), info.fd, &text);
+    ret = njs_module_read(console->engine->pool, info.fd, &text);
 
     (void) close(info.fd);
 
@@ -1293,10 +1293,10 @@ njs_module_loader(njs_vm_t *vm, njs_exte
     module = njs_vm_compile_module(vm, &info.file, &start,
                                    &text.start[text.length]);
 
-    njs_mp_free(njs_vm_memory_pool(vm), console->cwd.start);
+    njs_mp_free(console->engine->pool, console->cwd.start);
     console->cwd = prev_cwd;
 
-    njs_mp_free(njs_vm_memory_pool(vm), text.start);
+    njs_mp_free(console->engine->pool, text.start);
 
     return module;
 }
@@ -3716,7 +3716,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_valu
     njs_queue_remove(&ev->link);
     njs_rbtree_delete(&console->events, (njs_rbtree_part_t *) rb);
 
-    njs_mp_free(console->engine->pool, ev);
+    njs_mp_free(njs_vm_memory_pool(vm), ev);
 
     njs_value_undefined_set(retval);
 
@@ -3780,12 +3780,15 @@ njs_console_time(njs_console_t *console,
         link = njs_queue_next(link);
     }
 
-    label = njs_mp_alloc(console->engine->pool, sizeof(njs_timelabel_t));
+    label = njs_mp_alloc(console->engine->pool,
+                         sizeof(njs_timelabel_t) + name->length);
     if (njs_slow_path(label == NULL)) {
         return NJS_ERROR;
     }
 
-    label->name = *name;
+    label->name.start = (u_char *) label + sizeof(njs_timelabel_t);
+    memcpy(label->name.start, name->start, name->length);
+    label->name.length = name->length;
     label->time = njs_time();
 
     njs_queue_insert_tail(&console->labels, &label->link);


More information about the nginx-devel mailing list