summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-02-03 22:13:40 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-02-03 22:20:36 (GMT)
commit9b35b89fce2499d5352f5323baec53abbf9a4af2 (patch)
tree49dde922a235f7d11cc8db63c8e0ac1d26f530e7
parent10aa517f3a26dd9e4f96f78e62ba1c87e91c7243 (diff)
Fixed various memory leaks.
-rw-r--r--plugins/pychrysalide/pychrysa.c35
-rw-r--r--src/arch/processor.c8
-rw-r--r--src/common/array.c7
-rw-r--r--src/core/global.c2
-rw-r--r--src/format/format.c5
-rw-r--r--src/gui/editor.c2
-rw-r--r--src/main.c2
7 files changed, 52 insertions, 9 deletions
diff --git a/plugins/pychrysalide/pychrysa.c b/plugins/pychrysalide/pychrysa.c
index 928743d..723c2bc 100644
--- a/plugins/pychrysalide/pychrysa.c
+++ b/plugins/pychrysalide/pychrysa.c
@@ -94,6 +94,9 @@ static bool is_current_abi_suitable(void);
/* Définit la version attendue de GTK à charger dans Python. */
static bool set_version_for_gtk_namespace(const char *);
+/* Point de sortie pour l'initialisation de Python. */
+static void PyExit_pychrysalide(void);
+
/* Complète les chemins de recherches de Python. */
static void extend_python_path(const char *);
@@ -292,6 +295,27 @@ static bool set_version_for_gtk_namespace(const char *version)
* *
* Paramètres : - *
* *
+* Description : Point de sortie pour l'initialisation de Python. *
+* *
+* Retour : ? *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void PyExit_pychrysalide(void)
+{
+ extern void set_current_project(void *project);
+
+ set_current_project(NULL);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
* Description : Point d'entrée pour l'initialisation de Python. *
* *
* Retour : ? *
@@ -316,6 +340,7 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
{
PyObject *result; /* Module Python à retourner */
bool status; /* Bilan des inclusions */
+ int ret; /* Bilan de préparatifs */
GPluginModule *self; /* Représentation interne */
PluginStatusFlags self_flags; /* Fanions à mettre à jour */
@@ -427,12 +452,20 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
if (!status)
{
- PyErr_SetString(PyExc_SystemError, "fail to load all PyChrysalide components.");
+ PyErr_SetString(PyExc_SystemError, "failed to load all PyChrysalide components.");
return NULL;
}
if (_standalone)
{
+ ret = Py_AtExit(PyExit_pychrysalide);
+
+ if (ret == -1)
+ {
+ PyErr_SetString(PyExc_SystemError, "failed to register a cleanup function.");
+ return NULL;
+ }
+
/**
* Comme les sources locales sont prioritaires, le fichier "core/global.h"
* du greffon masque la fonction suivante, issue du corps principal du
diff --git a/src/arch/processor.c b/src/arch/processor.c
index 4d7bacc..05e3206 100644
--- a/src/arch/processor.c
+++ b/src/arch/processor.c
@@ -187,6 +187,11 @@ static void g_arch_processor_init(GArchProcessor *proc)
static void g_arch_processor_dispose(GArchProcessor *proc)
{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < proc->instr_count; i++)
+ g_clear_object(&proc->instructions[i]);
+
g_mutex_clear(&proc->mutex);
g_mutex_clear(&proc->error_mutex);
@@ -212,6 +217,9 @@ static void g_arch_processor_finalize(GArchProcessor *proc)
{
size_t i; /* Boucle de parcours */
+ if (proc->instructions != NULL)
+ free(proc->instructions);
+
if (proc->errors != NULL)
{
for (i = 0; i < proc->error_count; i++)
diff --git a/src/common/array.c b/src/common/array.c
index 8264101..3f721be 100644
--- a/src/common/array.c
+++ b/src/common/array.c
@@ -285,7 +285,7 @@ void copy_flat_array_items(flat_array_t **src, flat_array_t **dest, size_t size,
{
extended = EXTENDED_ARRAY(*src);
- new_ext = (ext_flat_array_t *)malloc(sizeof(ext_flat_array_t));
+ new_ext = malloc(sizeof(ext_flat_array_t));
new_ext->items = malloc(extended->count * size);
new_ext->count = extended->count;
@@ -387,7 +387,7 @@ void add_item_to_flat_array(flat_array_t **array, const void *item, size_t size)
{
if (FLAT_ARRAY_HAS_NO_INDEX(*array))
{
- extended = (ext_flat_array_t *)malloc(sizeof(ext_flat_array_t));
+ extended = malloc(sizeof(ext_flat_array_t));
extended->items = malloc(2 * size);
extended->count = 2;
@@ -456,7 +456,7 @@ void insert_item_into_flat_array(flat_array_t **array, void *item, size_t size,
{
if (FLAT_ARRAY_HAS_NO_INDEX(*array))
{
- extended = (ext_flat_array_t *)malloc(sizeof(ext_flat_array_t));
+ extended = malloc(sizeof(ext_flat_array_t));
extended->items = malloc(size);
extended->count = 1;
@@ -581,6 +581,7 @@ void rem_item_from_flat_array(flat_array_t **array, size_t index, size_t size)
else
memcpy(new, ((char *)extended->items) + size, size);
+ free(extended->items);
free(extended);
relock_flat_array(array, new);
diff --git a/src/core/global.c b/src/core/global.c
index 3777fd9..f61def6 100644
--- a/src/core/global.c
+++ b/src/core/global.c
@@ -283,8 +283,6 @@ GStudyProject *get_current_project(void)
void register_project_change_notification(current_project_change_cb notify)
{
- assert(_project_notify == NULL);
-
_project_notify = notify;
}
diff --git a/src/format/format.c b/src/format/format.c
index 261f152..cd71a21 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -156,10 +156,9 @@ static void g_binary_format_init(GBinFormat *format)
static void g_binary_format_dispose(GBinFormat *format)
{
- if (format->demangler != NULL)
- g_object_unref(format->demangler);
+ g_clear_object(&format->demangler);
- g_object_unref(format->info);
+ g_clear_object(&format->info);
g_rw_lock_clear(&format->syms_lock);
diff --git a/src/gui/editor.c b/src/gui/editor.c
index 205c78f..58dda53 100644
--- a/src/gui/editor.c
+++ b/src/gui/editor.c
@@ -408,6 +408,8 @@ static void on_destroy_editor(GtkWidget *widget, GObject *ref)
on_focus_out(widget, NULL, ref);
+ /* On évite de mettre à jour un affichage disparu... */
+ register_project_change_notification(NULL);
/* Si la boucle principale est bien lancée, on en sort ! */
if (gtk_main_level() > 0)
diff --git a/src/main.c b/src/main.c
index 34aea01..9ae3936 100644
--- a/src/main.c
+++ b/src/main.c
@@ -388,6 +388,8 @@ int main(int argc, char **argv)
else
gtk_main();
+ set_current_project(NULL);
+
bad_project:
if (server != NULL)