Skip to content

Commit 2bb93b5

Browse files
committed
QuickJS: fixed memory leak in js_periodic handler.
1 parent a2accf8 commit 2bb93b5

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

nginx/ngx_http_js_module.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ static ngx_http_request_t *ngx_http_qjs_request(JSValueConst val);
355355
static JSValue ngx_http_qjs_request_make(JSContext *cx, ngx_int_t proto_id,
356356
ngx_http_request_t *r);
357357
static void ngx_http_qjs_request_finalizer(JSRuntime *rt, JSValue val);
358+
static void ngx_http_qjs_periodic_finalizer(JSRuntime *rt, JSValue val);
358359
#endif
359360

360361
static ngx_pool_t *ngx_http_js_pool(ngx_http_request_t *r);
@@ -1097,7 +1098,7 @@ static JSClassDef ngx_http_qjs_request_class = {
10971098

10981099
static JSClassDef ngx_http_qjs_periodic_class = {
10991100
"PeriodicSession",
1100-
.finalizer = NULL,
1101+
.finalizer = ngx_http_qjs_periodic_finalizer,
11011102
};
11021103

11031104

@@ -7553,6 +7554,20 @@ ngx_http_qjs_request_finalizer(JSRuntime *rt, JSValue val)
75537554
}
75547555

75557556

7557+
static void
7558+
ngx_http_qjs_periodic_finalizer(JSRuntime *rt, JSValue val)
7559+
{
7560+
ngx_http_qjs_request_t *req;
7561+
7562+
req = JS_GetOpaque(val, NGX_QJS_CLASS_ID_HTTP_PERIODIC);
7563+
if (req == NULL) {
7564+
return;
7565+
}
7566+
7567+
js_free_rt(rt, req);
7568+
}
7569+
7570+
75567571
static ngx_engine_t *
75577572
ngx_engine_qjs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf,
75587573
njs_int_t proto_id, void *external)

nginx/ngx_stream_js_module.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ static ngx_stream_session_t *ngx_stream_qjs_session(JSValueConst val);
191191
static JSValue ngx_stream_qjs_session_make(JSContext *cx, ngx_int_t proto_id,
192192
ngx_stream_session_t *s);
193193
static void ngx_stream_qjs_session_finalizer(JSRuntime *rt, JSValue val);
194+
static void ngx_stream_qjs_periodic_finalizer(JSRuntime *rt, JSValue val);
194195

195196
#endif
196197

@@ -813,7 +814,7 @@ static JSClassDef ngx_stream_qjs_session_class = {
813814

814815
static JSClassDef ngx_stream_qjs_periodic_class = {
815816
"Periodic",
816-
.finalizer = NULL,
817+
.finalizer = ngx_stream_qjs_periodic_finalizer,
817818
};
818819

819820

@@ -2812,6 +2813,20 @@ ngx_stream_qjs_session_finalizer(JSRuntime *rt, JSValue val)
28122813
}
28132814

28142815

2816+
static void
2817+
ngx_stream_qjs_periodic_finalizer(JSRuntime *rt, JSValue val)
2818+
{
2819+
ngx_stream_qjs_session_t *ses;
2820+
2821+
ses = JS_GetOpaque(val, NGX_QJS_CLASS_ID_STREAM_PERIODIC);
2822+
if (ses == NULL) {
2823+
return;
2824+
}
2825+
2826+
js_free_rt(rt, ses);
2827+
}
2828+
2829+
28152830
static ngx_engine_t *
28162831
ngx_engine_qjs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf,
28172832
njs_int_t proto_id, void *external)

0 commit comments

Comments
 (0)