From bfc88545c8e163ab3ce8e87105b49bf799ef8275 Mon Sep 17 00:00:00 2001 From: gambas Date: Mon, 24 Dec 2018 17:57:36 +0100 Subject: [PATCH] Correctly clear observer reference on the observed object when it is freed. [INTERPRETER] * BUG: Correctly clear observer reference on the observed object when it is freed. * BUG: Clear environment variables set by the interpreter, as they can be read by the shared libraries exit routines after main() has been terminated. --- main/gbx/gbx_c_observer.c | 2 +- main/gbx/gbx_local.c | 20 +++++++++++++++++--- main/gbx/gbx_object.c | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/main/gbx/gbx_c_observer.c b/main/gbx/gbx_c_observer.c index b77a65c08..1b6350b39 100644 --- a/main/gbx/gbx_c_observer.c +++ b/main/gbx/gbx_c_observer.c @@ -47,7 +47,7 @@ void COBSERVER_attach(COBSERVER *this, void *parent, const char *name) #if DEBUG_ME fprintf(stderr, "COBSERVER_attach: %p: %s %p\n", this, parent ? OBJECT_class(parent)->name : "", parent); #endif - if (this->event) + if (this->object && this->event) EVENT_search(OBJECT_class(this->object), this->event, name, parent); } diff --git a/main/gbx/gbx_local.c b/main/gbx/gbx_local.c index b45f807c2..76b43b63e 100644 --- a/main/gbx/gbx_local.c +++ b/main/gbx/gbx_local.c @@ -602,11 +602,25 @@ void LOCAL_init(void) void LOCAL_exit(void) { - STRING_free(&env_LANG); - STRING_free(&env_LC_ALL); - STRING_free(&env_LANGUAGE); + if (env_LANG) + { + unsetenv("LANG"); + STRING_free(&env_LANG); + } + if (env_LC_ALL) + { + unsetenv("LC_ALL"); + STRING_free(&env_LC_ALL); + } + if (env_LANGUAGE) + { + unsetenv("LANGUAGE"); + STRING_free(&env_LANGUAGE); + } + if (!LOCAL_is_UTF8) STRING_free(&LOCAL_encoding); + STRING_free(&_lang); free_local_info(); } diff --git a/main/gbx/gbx_object.c b/main/gbx/gbx_object.c index fdc777076..1c6afddf6 100644 --- a/main/gbx/gbx_object.c +++ b/main/gbx/gbx_object.c @@ -196,6 +196,7 @@ static void remove_observers(OBJECT *ob) #if DEBUG_EVENT fprintf(stderr, "Remove observer %p %d: %p: %p\n", obs, (int)obs->ob.ref, ob, obs->object); #endif + obs->object = NULL; OBJECT_UNREF(obs); obs = next; }