arguments, ncaptures, &groups,
replace, retval);
- if (njs_object_slots(r)) {
- njs_regexp_exec_result_free(vm, njs_array(r));
- }
-
} else {
ret = njs_array_expand(vm, array, 0,
njs_is_defined(&groups) ? 3 : 2);
next_pos = pos + (int64_t) m.length;
}
+
+ if (!func_replace && njs_object_slots(r)) {
+ /*
+ * Doing free here ONLY for non-function replace, because
+ * otherwise we cannot be certain the result of match
+ * was not stored elsewhere.
+ */
+ njs_regexp_exec_result_free(vm, njs_array(r));
+ }
}
if (next_pos < (int64_t) s.size) {