Gabriel Ivăncescu : jscript: Release all globals when the script is uninitialized.
Alexandre Julliard
julliard at winehq.org
Fri Jun 3 15:53:09 CDT 2022
Module: wine
Branch: master
Commit: 79e51d6bc50bc1d519c275944f5b87ccc503c216
URL: https://source.winehq.org/git/wine.git/?a=commit;h=79e51d6bc50bc1d519c275944f5b87ccc503c216
Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date: Thu Jun 2 20:00:47 2022 +0300
jscript: Release all globals when the script is uninitialized.
Most of these globals were leaking before as they were never freed at all.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/jscript/jscript.c | 31 ++++++++++++------------------
dlls/jscript/jscript.h | 50 +++++++++++++++++++++++++++---------------------
dlls/jscript/tests/run.c | 1 -
3 files changed, 40 insertions(+), 42 deletions(-)
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index d6028e69888..8a54f32f234 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -91,6 +91,17 @@ void script_release(script_ctx_t *ctx)
heap_free(ctx);
}
+static void script_globals_release(script_ctx_t *ctx)
+{
+ unsigned i;
+ for(i = 0; i < ARRAY_SIZE(ctx->global_objects); i++) {
+ if(ctx->global_objects[i]) {
+ jsdisp_release(ctx->global_objects[i]);
+ ctx->global_objects[i] = NULL;
+ }
+ }
+}
+
static void change_state(JScript *This, SCRIPTSTATE state)
{
if(This->ctx->state == state)
@@ -483,25 +494,7 @@ static void decrease_state(JScript *This, SCRIPTSTATE state)
This->ctx->site = NULL;
}
- if(This->ctx->map_prototype) {
- jsdisp_release(This->ctx->map_prototype);
- This->ctx->map_prototype = NULL;
- }
-
- if(This->ctx->set_prototype) {
- jsdisp_release(This->ctx->set_prototype);
- This->ctx->set_prototype = NULL;
- }
-
- if(This->ctx->object_prototype) {
- jsdisp_release(This->ctx->object_prototype);
- This->ctx->object_prototype = NULL;
- }
-
- if(This->ctx->global) {
- jsdisp_release(This->ctx->global);
- This->ctx->global = NULL;
- }
+ script_globals_release(This->ctx);
/* FALLTHROUGH */
case SCRIPTSTATE_UNINITIALIZED:
change_state(This, state);
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 000bcc287f4..0f8baea0188 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -387,29 +387,35 @@ struct _script_ctx_t {
DWORD last_match_index;
DWORD last_match_length;
- jsdisp_t *global;
- jsdisp_t *function_constr;
- jsdisp_t *array_constr;
- jsdisp_t *bool_constr;
- jsdisp_t *date_constr;
- jsdisp_t *enumerator_constr;
- jsdisp_t *error_constr;
- jsdisp_t *eval_error_constr;
- jsdisp_t *range_error_constr;
- jsdisp_t *reference_error_constr;
- jsdisp_t *regexp_error_constr;
- jsdisp_t *syntax_error_constr;
- jsdisp_t *type_error_constr;
- jsdisp_t *uri_error_constr;
- jsdisp_t *number_constr;
- jsdisp_t *object_constr;
- jsdisp_t *object_prototype;
- jsdisp_t *regexp_constr;
- jsdisp_t *string_constr;
- jsdisp_t *vbarray_constr;
- jsdisp_t *map_prototype;
- jsdisp_t *set_prototype;
+ union {
+ struct {
+ jsdisp_t *global;
+ jsdisp_t *function_constr;
+ jsdisp_t *array_constr;
+ jsdisp_t *bool_constr;
+ jsdisp_t *date_constr;
+ jsdisp_t *enumerator_constr;
+ jsdisp_t *error_constr;
+ jsdisp_t *eval_error_constr;
+ jsdisp_t *range_error_constr;
+ jsdisp_t *reference_error_constr;
+ jsdisp_t *regexp_error_constr;
+ jsdisp_t *syntax_error_constr;
+ jsdisp_t *type_error_constr;
+ jsdisp_t *uri_error_constr;
+ jsdisp_t *number_constr;
+ jsdisp_t *object_constr;
+ jsdisp_t *object_prototype;
+ jsdisp_t *regexp_constr;
+ jsdisp_t *string_constr;
+ jsdisp_t *vbarray_constr;
+ jsdisp_t *map_prototype;
+ jsdisp_t *set_prototype;
+ };
+ jsdisp_t *global_objects[22];
+ };
};
+C_ASSERT(RTL_SIZEOF_THROUGH_FIELD(script_ctx_t, set_prototype) == RTL_SIZEOF_THROUGH_FIELD(script_ctx_t, global_objects));
void script_release(script_ctx_t*) DECLSPEC_HIDDEN;
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index f7ad1feb408..ec054f03d0d 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -3293,7 +3293,6 @@ static void test_invokeex(void)
str = SysAllocString(L"call");
hres = IDispatchEx_GetDispID(dispex, str, 0, &func_id);
SysFreeString(str);
- todo_wine
ok(hres == E_UNEXPECTED, "GetDispID failed: %08lx\n", hres);
IDispatchEx_Release(dispex);
More information about the wine-cvs
mailing list