Skip to content

Commit 1d36e23

Browse files
committed
QuickJS: calling njs_chb_destroy() in qjs_string_create_chb() internally.
No functional changes.
1 parent 1b7adef commit 1d36e23

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

external/qjs_query_string_module.c

+3-14
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ static JSValue
171171
qjs_query_string_decode(JSContext *cx, const u_char *start, size_t size)
172172
{
173173
u_char *dst;
174-
JSValue ret;
175174
uint32_t cp;
176175
njs_chb_t chain;
177176
const u_char *p, *end;
@@ -250,11 +249,7 @@ qjs_query_string_decode(JSContext *cx, const u_char *start, size_t size)
250249
}
251250

252251

253-
ret = qjs_string_create_chb(cx, &chain);
254-
255-
njs_chb_destroy(&chain);
256-
257-
return ret;
252+
return qjs_string_create_chb(cx, &chain);
258253
}
259254

260255

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

282277
ret = qjs_string_create_chb(cx, &chain);
283278

284-
njs_chb_destroy(&chain);
285-
286279
JS_FreeCString(cx, (char *) str.start);
287280

288281
return ret;
@@ -733,7 +726,7 @@ qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
733726
{
734727
int rc;
735728
uint32_t n, length;
736-
JSValue key, val, ret;
729+
JSValue key, val;
737730
njs_str_t sep_val, eq_val;
738731
njs_chb_t chain;
739732
JSPropertyEnum *ptab;
@@ -809,11 +802,7 @@ qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
809802
qjs_free_prop_enum(cx, ptab, length);
810803
}
811804

812-
ret = qjs_string_create_chb(cx, &chain);
813-
814-
njs_chb_destroy(&chain);
815-
816-
return ret;
805+
return qjs_string_create_chb(cx, &chain);
817806

818807
fail:
819808

nginx/ngx_http_js_module.c

+12-18
Original file line numberDiff line numberDiff line change
@@ -6400,10 +6400,9 @@ ngx_http_qjs_header_generic(JSContext *cx, ngx_http_request_t *r,
64006400
ngx_list_t *headers, ngx_table_elt_t **ph, ngx_str_t *name,
64016401
JSPropertyDescriptor *pdesc, unsigned flags)
64026402
{
6403-
int ret;
64046403
u_char sep;
6405-
njs_chb_t chain;
64066404
JSValue val;
6405+
njs_chb_t chain;
64076406
ngx_uint_t i;
64086407
ngx_list_part_t *part;
64096408
ngx_table_elt_t *header, *h;
@@ -6493,6 +6492,10 @@ ngx_http_qjs_header_generic(JSContext *cx, ngx_http_request_t *r,
64936492
return 1;
64946493
}
64956494

6495+
if (pdesc == NULL) {
6496+
return 1;
6497+
}
6498+
64966499
NJS_CHB_CTX_INIT(&chain, cx);
64976500

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

6506-
ret = 1;
6507-
6508-
if (pdesc != NULL) {
6509-
pdesc->flags = JS_PROP_ENUMERABLE;
6510-
pdesc->getter = JS_UNDEFINED;
6511-
pdesc->setter = JS_UNDEFINED;
6512-
pdesc->value = qjs_string_create_chb(cx, &chain);
6513-
if (JS_IsException(pdesc->value)) {
6514-
ret = -1;
6515-
goto done;
6516-
}
6509+
pdesc->flags = JS_PROP_ENUMERABLE;
6510+
pdesc->getter = JS_UNDEFINED;
6511+
pdesc->setter = JS_UNDEFINED;
6512+
pdesc->value = qjs_string_create_chb(cx, &chain);
6513+
if (JS_IsException(pdesc->value)) {
6514+
return -1;
65176515
}
65186516

6519-
done:
6520-
6521-
njs_chb_destroy(&chain);
6522-
6523-
return ret;
6517+
return 1;
65246518
}
65256519

65266520

src/qjs.c

+2
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ qjs_string_create_chb(JSContext *cx, njs_chb_t *chain)
10151015
njs_str_t str;
10161016

10171017
ret = njs_chb_join(chain, &str);
1018+
njs_chb_destroy(chain);
1019+
10181020
if (ret != NJS_OK) {
10191021
return JS_ThrowInternalError(cx, "failed to create string");
10201022
}

0 commit comments

Comments
 (0)