Skip to content

Commit df26647

Browse files
committed
QuickJS: add njs_chb_destroy() in qjs_string_create_chb() internally.
No functional changes.
1 parent 9010aee commit df26647

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

external/qjs_query_string_module.c

Lines changed: 3 additions & 14 deletions
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;
@@ -746,7 +739,7 @@ qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
746739
{
747740
int rc;
748741
uint32_t n, length;
749-
JSValue key, val, ret;
742+
JSValue key, val;
750743
njs_str_t sep_val, eq_val;
751744
njs_chb_t chain;
752745
JSPropertyEnum *ptab;
@@ -822,11 +815,7 @@ qjs_query_string_stringify_internal(JSContext *cx, JSValue obj, njs_str_t *sep,
822815
qjs_free_prop_enum(cx, ptab, length);
823816
}
824817

825-
ret = qjs_string_create_chb(cx, &chain);
826-
827-
njs_chb_destroy(&chain);
828-
829-
return ret;
818+
return qjs_string_create_chb(cx, &chain);
830819

831820
fail:
832821

nginx/ngx_http_js_module.c

Lines changed: 6 additions & 11 deletions
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;
@@ -6503,24 +6502,20 @@ ngx_http_qjs_header_generic(JSContext *cx, ngx_http_request_t *r,
65036502
njs_chb_append_literal(&chain, " ");
65046503
}
65056504

6506-
ret = 1;
6507-
65086505
if (pdesc != NULL) {
65096506
pdesc->flags = JS_PROP_ENUMERABLE;
65106507
pdesc->getter = JS_UNDEFINED;
65116508
pdesc->setter = JS_UNDEFINED;
65126509
pdesc->value = qjs_string_create_chb(cx, &chain);
65136510
if (JS_IsException(pdesc->value)) {
6514-
ret = -1;
6515-
goto done;
6511+
return -1;
65166512
}
6517-
}
65186513

6519-
done:
6520-
6521-
njs_chb_destroy(&chain);
6514+
} else {
6515+
njs_chb_destroy(&chain);
6516+
}
65226517

6523-
return ret;
6518+
return 1;
65246519
}
65256520

65266521

src/qjs.c

Lines changed: 2 additions & 0 deletions
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)