Skip to content

QuickJS: calling njs_chb_destroy() in qjs_string_create_chb() internally. #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions external/qjs_query_string_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ static JSValue
qjs_query_string_decode(JSContext *cx, const u_char *start, size_t size)
{
u_char *dst;
JSValue ret;
uint32_t cp;
njs_chb_t chain;
const u_char *p, *end;
Expand Down Expand Up @@ -250,11 +249,7 @@ qjs_query_string_decode(JSContext *cx, const u_char *start, size_t size)
}


ret = qjs_string_create_chb(cx, &chain);

njs_chb_destroy(&chain);

return ret;
return qjs_string_create_chb(cx, &chain);
}


Expand All @@ -281,8 +276,6 @@ qjs_query_string_escape(JSContext *cx, JSValueConst this_val, int argc,

ret = qjs_string_create_chb(cx, &chain);

njs_chb_destroy(&chain);

JS_FreeCString(cx, (char *) str.start);

return ret;
Expand Down Expand Up @@ -733,7 +726,7 @@ qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
{
int rc;
uint32_t n, length;
JSValue key, val, ret;
JSValue key, val;
njs_str_t sep_val, eq_val;
njs_chb_t chain;
JSPropertyEnum *ptab;
Expand Down Expand Up @@ -809,11 +802,7 @@ qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
qjs_free_prop_enum(cx, ptab, length);
}

ret = qjs_string_create_chb(cx, &chain);

njs_chb_destroy(&chain);

return ret;
return qjs_string_create_chb(cx, &chain);

fail:

Expand Down
30 changes: 12 additions & 18 deletions nginx/ngx_http_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -6400,10 +6400,9 @@ ngx_http_qjs_header_generic(JSContext *cx, ngx_http_request_t *r,
ngx_list_t *headers, ngx_table_elt_t **ph, ngx_str_t *name,
JSPropertyDescriptor *pdesc, unsigned flags)
{
int ret;
u_char sep;
njs_chb_t chain;
JSValue val;
njs_chb_t chain;
ngx_uint_t i;
ngx_list_part_t *part;
ngx_table_elt_t *header, *h;
Expand Down Expand Up @@ -6493,6 +6492,10 @@ ngx_http_qjs_header_generic(JSContext *cx, ngx_http_request_t *r,
return 1;
}

if (pdesc == NULL) {
return 1;
}

NJS_CHB_CTX_INIT(&chain, cx);

sep = flags & NJS_HEADER_SEMICOLON ? ';' : ',';
Expand All @@ -6503,24 +6506,15 @@ ngx_http_qjs_header_generic(JSContext *cx, ngx_http_request_t *r,
njs_chb_append_literal(&chain, " ");
}

ret = 1;

if (pdesc != NULL) {
pdesc->flags = JS_PROP_ENUMERABLE;
pdesc->getter = JS_UNDEFINED;
pdesc->setter = JS_UNDEFINED;
pdesc->value = qjs_string_create_chb(cx, &chain);
if (JS_IsException(pdesc->value)) {
ret = -1;
goto done;
}
pdesc->flags = JS_PROP_ENUMERABLE;
pdesc->getter = JS_UNDEFINED;
pdesc->setter = JS_UNDEFINED;
pdesc->value = qjs_string_create_chb(cx, &chain);
if (JS_IsException(pdesc->value)) {
return -1;
}

done:

njs_chb_destroy(&chain);

return ret;
return 1;
}


Expand Down
2 changes: 2 additions & 0 deletions src/qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ qjs_string_create_chb(JSContext *cx, njs_chb_t *chain)
njs_str_t str;

ret = njs_chb_join(chain, &str);
njs_chb_destroy(chain);

if (ret != NJS_OK) {
return JS_ThrowInternalError(cx, "failed to create string");
}
Expand Down