]> git.kaiwu.me - njs.git/commitdiff
QuickJS: fixed memory leak in js_periodic handler.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 20 Feb 2025 01:36:46 +0000 (17:36 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 20 Feb 2025 18:17:00 +0000 (10:17 -0800)
nginx/ngx_http_js_module.c
nginx/ngx_stream_js_module.c

index 7cd874019f204578e1f3a34fc7ebcd0b2c69754e..cdc668c58e739be7ba6f14772c3e736989f12b3f 100644 (file)
@@ -355,6 +355,7 @@ static ngx_http_request_t *ngx_http_qjs_request(JSValueConst val);
 static JSValue ngx_http_qjs_request_make(JSContext *cx, ngx_int_t proto_id,
     ngx_http_request_t *r);
 static void ngx_http_qjs_request_finalizer(JSRuntime *rt, JSValue val);
+static void ngx_http_qjs_periodic_finalizer(JSRuntime *rt, JSValue val);
 #endif
 
 static ngx_pool_t *ngx_http_js_pool(ngx_http_request_t *r);
@@ -1097,7 +1098,7 @@ static JSClassDef ngx_http_qjs_request_class = {
 
 static JSClassDef ngx_http_qjs_periodic_class = {
     "PeriodicSession",
-    .finalizer = NULL,
+    .finalizer = ngx_http_qjs_periodic_finalizer,
 };
 
 
@@ -7553,6 +7554,20 @@ ngx_http_qjs_request_finalizer(JSRuntime *rt, JSValue val)
 }
 
 
+static void
+ngx_http_qjs_periodic_finalizer(JSRuntime *rt, JSValue val)
+{
+    ngx_http_qjs_request_t  *req;
+
+    req = JS_GetOpaque(val, NGX_QJS_CLASS_ID_HTTP_PERIODIC);
+    if (req == NULL) {
+        return;
+    }
+
+    js_free_rt(rt, req);
+}
+
+
 static ngx_engine_t *
 ngx_engine_qjs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf,
     njs_int_t proto_id, void *external)
index 59a3e9d22684d8e054020adf7faba5f80ae80b53..db00b9226b22044e19fb6e04632170ac0f3d153f 100644 (file)
@@ -191,6 +191,7 @@ static ngx_stream_session_t *ngx_stream_qjs_session(JSValueConst val);
 static JSValue ngx_stream_qjs_session_make(JSContext *cx, ngx_int_t proto_id,
     ngx_stream_session_t *s);
 static void ngx_stream_qjs_session_finalizer(JSRuntime *rt, JSValue val);
+static void ngx_stream_qjs_periodic_finalizer(JSRuntime *rt, JSValue val);
 
 #endif
 
@@ -813,7 +814,7 @@ static JSClassDef ngx_stream_qjs_session_class = {
 
 static JSClassDef ngx_stream_qjs_periodic_class = {
     "Periodic",
-    .finalizer = NULL,
+    .finalizer = ngx_stream_qjs_periodic_finalizer,
 };
 
 
@@ -2812,6 +2813,20 @@ ngx_stream_qjs_session_finalizer(JSRuntime *rt, JSValue val)
 }
 
 
+static void
+ngx_stream_qjs_periodic_finalizer(JSRuntime *rt, JSValue val)
+{
+    ngx_stream_qjs_session_t  *ses;
+
+    ses = JS_GetOpaque(val, NGX_QJS_CLASS_ID_STREAM_PERIODIC);
+    if (ses == NULL) {
+        return;
+    }
+
+    js_free_rt(rt, ses);
+}
+
+
 static ngx_engine_t *
 ngx_engine_qjs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf,
     njs_int_t proto_id, void *external)