summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide')
-rw-r--r--plugins/pychrysalide/access.c22
-rw-r--r--plugins/pychrysalide/access.h3
-rw-r--r--plugins/pychrysalide/analysis/project.c3
-rw-r--r--plugins/pychrysalide/helpers.c4
-rw-r--r--plugins/pychrysalide/plugin.c37
-rw-r--r--plugins/pychrysalide/pychrysa.c24
6 files changed, 77 insertions, 16 deletions
diff --git a/plugins/pychrysalide/access.c b/plugins/pychrysalide/access.c
index bfaf160..4efa9c7 100644
--- a/plugins/pychrysalide/access.c
+++ b/plugins/pychrysalide/access.c
@@ -95,8 +95,6 @@ void register_access_to_python_module(const char *path, PyObject *mod)
access.path = path;
access.mod = mod;
- Py_INCREF(mod);
-
_pychrysalide_modules = qinsert(_pychrysalide_modules, &_pychrysalide_count,
sizeof(module_access), (__compar_fn_t)compare_python_module_accesses,
&access);
@@ -135,3 +133,23 @@ PyObject *get_access_to_python_module(const char *path)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Supprime tous les accès rapide aux modules Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void clear_all_accesses_to_python_modules(void)
+{
+ if (_pychrysalide_modules != NULL)
+ free(_pychrysalide_modules);
+
+}
diff --git a/plugins/pychrysalide/access.h b/plugins/pychrysalide/access.h
index 492664d..9a842e4 100644
--- a/plugins/pychrysalide/access.h
+++ b/plugins/pychrysalide/access.h
@@ -35,6 +35,9 @@ void register_access_to_python_module(const char *, PyObject *);
/* Fournit la référence à un module Python défini. */
PyObject *get_access_to_python_module(const char *path);
+/* Supprime tous les accès rapide aux modules Python. */
+void clear_all_accesses_to_python_modules(void);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ACCESS_H */
diff --git a/plugins/pychrysalide/analysis/project.c b/plugins/pychrysalide/analysis/project.c
index 9046bf3..98610d5 100644
--- a/plugins/pychrysalide/analysis/project.c
+++ b/plugins/pychrysalide/analysis/project.c
@@ -308,6 +308,9 @@ static PyObject *py_study_project_get_contents(PyObject *self, void *closure)
}
+ if (contents != NULL)
+ free(contents);
+
return result;
}
diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c
index f744475..48b805c 100644
--- a/plugins/pychrysalide/helpers.c
+++ b/plugins/pychrysalide/helpers.c
@@ -434,6 +434,8 @@ bool register_python_module_methods(PyObject *module, PyMethodDef *defs)
if (result)
{
+ Py_INCREF(item);
+
ret = PyDict_SetItemString(features_dict, iter->ml_name, item);
result = (ret == 0);
assert(result);
@@ -483,6 +485,8 @@ static bool include_python_type_into_features(PyObject *dict, PyTypeObject *type
result = (item != NULL);
assert(result);
+ Py_INCREF(item);
+
ret = PyDict_SetItemString(features_dict, name, item);
result = (ret == 0);
assert(result);
diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c
index 51da910..9352924 100644
--- a/plugins/pychrysalide/plugin.c
+++ b/plugins/pychrysalide/plugin.c
@@ -94,9 +94,6 @@ struct _GPythonPlugin
{
GPluginModule parent; /* Instance parente */
- PyObject *module; /* Script Python chargé */
- PyObject *instance; /* Instance Python du greffon */
-
};
@@ -551,6 +548,8 @@ static void py_plugin_module_handle_binary_content_wrapper(const GPluginModule *
Py_XDECREF(value);
Py_DECREF(args);
+ Py_DECREF(pyobj);
+
PyGILState_Release(gstate);
}
@@ -597,6 +596,8 @@ static void py_plugin_module_handle_loaded_content_wrapper(const GPluginModule *
Py_XDECREF(value);
Py_DECREF(args);
+ Py_DECREF(pyobj);
+
PyGILState_Release(gstate);
}
@@ -643,6 +644,8 @@ static bool py_plugin_module_handle_binary_format_analysis_wrapper(const GPlugin
Py_XDECREF(value);
Py_DECREF(args);
+ Py_DECREF(pyobj);
+
PyGILState_Release(gstate);
return true;
@@ -691,6 +694,8 @@ static bool py_plugin_module_preload_binary_format_wrapper(const GPluginModule *
Py_XDECREF(value);
Py_DECREF(args);
+ Py_DECREF(pyobj);
+
PyGILState_Release(gstate);
return true;
@@ -735,6 +740,8 @@ static void py_plugin_module_attach_debug_format_wrapper(const GPluginModule *pl
Py_XDECREF(value);
Py_DECREF(args);
+ Py_DECREF(pyobj);
+
PyGILState_Release(gstate);
}
@@ -781,6 +788,8 @@ static void py_plugin_module_process_disassembly_event_wrapper(const GPluginModu
Py_XDECREF(value);
Py_DECREF(args);
+ Py_DECREF(pyobj);
+
PyGILState_Release(gstate);
}
@@ -903,9 +912,6 @@ static void g_python_plugin_dispose(GPythonPlugin *plugin)
if (tstate != NULL)
PyEval_RestoreThread(tstate);
- Py_XDECREF(plugin->instance);
- plugin->instance = NULL;
-
if (tstate != NULL)
PyEval_SaveThread();
@@ -930,15 +936,20 @@ static void g_python_plugin_finalize(GPythonPlugin *plugin)
{
plugin_interface *final; /* Interface finale conservée */
- Py_XDECREF(plugin->module);
-
final = (plugin_interface *)G_PLUGIN_MODULE(plugin)->interface;
if (final != NULL)
{
+ free(final->name);
+ free(final->desc);
+ free(final->version);
+
assert(final->required_count == 1);
free(final->required);
+ if (final->actions != NULL)
+ free(final->actions);
+
free(final);
}
@@ -1025,10 +1036,14 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename)
G_PLUGIN_MODULE(result)->filename = strdup(filename);
- result->module = module;
- result->instance = instance;
+ /**
+ * L'instance Python et l'objet GLib résultante sont un même PyGObject.
+ *
+ * Donc pas besoin de toucher au comptage des références ici, la libération
+ * se réalisera à la fin, quand l'objet GLib sera libéré.
+ */
- Py_INCREF(instance);
+ Py_DECREF(module);
return G_PLUGIN_MODULE(result);
diff --git a/plugins/pychrysalide/pychrysa.c b/plugins/pychrysalide/pychrysa.c
index 4cb18d9..3e14add 100644
--- a/plugins/pychrysalide/pychrysa.c
+++ b/plugins/pychrysalide/pychrysa.c
@@ -306,13 +306,22 @@ static bool set_version_for_gtk_namespace(const char *version)
static void PyExit_pychrysalide(void)
{
+ assert(_standalone);
+
extern void set_current_project(void *project);
set_current_project(NULL);
#ifdef TRACK_GOBJECT_LEAKS
- if (_standalone)
- dump_remaining_gtypes();
+ remember_gtypes_for_leaks();
+#endif
+
+ exit_all_plugins();
+
+ unload_all_basic_components();
+
+#ifdef TRACK_GOBJECT_LEAKS
+ dump_remaining_gtypes();
#endif
}
@@ -500,7 +509,12 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
load_remaning_plugins();
- g_object_unref(G_OBJECT(self));
+ /**
+ * On laisse fuir ici la référence sur self afin d'avoir
+ * l'assurance que le greffon se déchargera toujours en dernier.
+ *
+ * La fuite mémoire est au final évitée dans PyExit_pychrysalide().
+ */
}
@@ -657,6 +671,8 @@ static void load_python_plugins(GPluginModule *plugin)
}
+ free(paths);
+
}
@@ -737,6 +753,8 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin)
{
+ clear_all_accesses_to_python_modules();
+
Py_XDECREF(_chrysalide_module);
}