qulogic/gplugin

Merged in develop/asan (pull request #12)
develop
2019-02-02, Gary Kramlich
8bef9b3f0bd1
Merged in develop/asan (pull request #12)

Fix various memory issues

Approved-by: Gary Kramlich
--- a/gplugin/gplugin-file-tree.c Fri Feb 01 02:23:51 2019 +0000
+++ b/gplugin/gplugin-file-tree.c Sat Feb 02 07:37:10 2019 +0000
@@ -60,10 +60,12 @@
* Helpers
*****************************************************************************/
static gboolean
-gplugin_file_tree_free_leaves(GNode *n, G_GNUC_UNUSED gpointer d) {
+gplugin_file_tree_free_leaves(GNode *n, gpointer d) {
+ GNode *root = d;
GPluginFileTreeEntry *e = n->data;
- gplugin_file_tree_entry_free(e);
+ if (n != root)
+ gplugin_file_tree_entry_free(e);
return FALSE;
}
@@ -144,12 +146,10 @@
gplugin_file_tree_free(GNode *root) {
g_return_if_fail(root);
- if(root->data) {
- g_node_traverse(root, G_POST_ORDER, G_TRAVERSE_LEAVES, -1,
- gplugin_file_tree_free_leaves, NULL);
- g_node_traverse(root, G_POST_ORDER, G_TRAVERSE_NON_LEAVES, -1,
- gplugin_file_tree_free_non_leaves, NULL);
- }
+ g_node_traverse(root, G_POST_ORDER, G_TRAVERSE_LEAVES, -1,
+ gplugin_file_tree_free_leaves, root);
+ g_node_traverse(root, G_POST_ORDER, G_TRAVERSE_NON_LEAVES, -1,
+ gplugin_file_tree_free_non_leaves, NULL);
g_node_destroy(root);
}
--- a/gplugin/gplugin-manager.c Fri Feb 01 02:23:51 2019 +0000
+++ b/gplugin/gplugin-manager.c Sat Feb 02 07:37:10 2019 +0000
@@ -477,9 +477,9 @@
}
/* now insert into our view */
- g_hash_table_insert(manager->plugins_filename_view,
- real_filename,
- g_object_ref(G_OBJECT(plugin)));
+ g_hash_table_replace(manager->plugins_filename_view,
+ real_filename,
+ g_object_ref(G_OBJECT(plugin)));
/* Grab the list of plugins with our id and prepend the new
* plugin to it before updating it.
@@ -487,10 +487,12 @@
l = g_hash_table_lookup(manager->plugins, id);
for(ll = l; ll; ll = ll->next) {
GPluginPlugin *splugin = GPLUGIN_PLUGIN(ll->data);
- const gchar *sfilename = gplugin_plugin_get_filename(splugin);
+ gchar *sfilename = gplugin_plugin_get_filename(splugin);
if(!g_strcmp0(real_filename, sfilename))
seen = TRUE;
+
+ g_free(sfilename);
}
if(!seen) {
l = g_slist_prepend(l, g_object_ref(plugin));
@@ -639,8 +641,12 @@
/* now look for a plugin matching the id */
matches = gplugin_manager_find_plugins(oid);
- if(matches == NULL)
+ if(matches == NULL) {
+ g_free(oid);
+ g_free(oop);
+ g_free(over);
continue;
+ }
/* now iterate the matches and check if we need to check their
* version.
@@ -699,6 +705,10 @@
}
}
+ g_free(oid);
+ g_free(oop);
+ g_free(over);
+
if(found)
break;
}
@@ -1056,7 +1066,7 @@
* a value of the plugin itself.
*/
manager->plugins_filename_view =
- g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
+ g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
/* The loaders hash table is keyed on the supported extensions of the
* loader. Which means that a loader that supports multiple extensions
--- a/gplugin/gplugin-version.c Fri Feb 01 02:23:51 2019 +0000
+++ b/gplugin/gplugin-version.c Sat Feb 02 07:37:10 2019 +0000
@@ -107,6 +107,8 @@
if(extra)
*extra = g_match_info_fetch_named(info, "extra");
+ g_match_info_unref(info);
+
return TRUE;
}
--- a/gplugin/tests/test-option-group.c Fri Feb 01 02:23:51 2019 +0000
+++ b/gplugin/tests/test-option-group.c Sat Feb 02 07:37:10 2019 +0000
@@ -29,15 +29,13 @@
GOptionGroup *group = NULL;
GList *paths = NULL, *l1 = NULL, *l2 = NULL;
gchar **argv = NULL;
- gint argc = 0;
argv = g_strsplit(args, ",", 0);
- argc = g_strv_length(argv);
ctx = g_option_context_new(NULL);
group = gplugin_get_option_group();
g_option_context_add_group(ctx, group);
- g_option_context_parse(ctx, &argc, &argv, &error);
+ g_option_context_parse_strv(ctx, &argv, &error);
g_option_context_free(ctx);
g_strfreev(argv);
--- a/gplugin/tests/test-plugin-info.c Fri Feb 01 02:23:51 2019 +0000
+++ b/gplugin/tests/test-plugin-info.c Sat Feb 02 07:37:10 2019 +0000
@@ -66,6 +66,7 @@
for(i = 0; expected[i]; i++)
g_assert_cmpstr(tmp[i], ==, expected[i]);
+ g_strfreev(got);
g_strfreev(tmp);
}
--- a/python/gplugin-python-loader.c Fri Feb 01 02:23:51 2019 +0000
+++ b/python/gplugin-python-loader.c Sat Feb 02 07:37:10 2019 +0000
@@ -50,7 +50,7 @@
}
static GPluginPlugin *
-gplugin_python_loader_query(G_GNUC_UNUSED GPluginLoader *loader,
+gplugin_python_loader_query(GPluginLoader *loader,
const gchar *filename,
G_GNUC_UNUSED GError **error)
{
@@ -82,6 +82,10 @@
g_warning(_("Failed to query %s"), filename);
PyErr_Print();
+ /* clean some stuff up */
+ g_free(module_name);
+ Py_DECREF(package_list);
+
pyg_gil_state_release(state);
return NULL;
@@ -101,6 +105,7 @@
g_warning(_("Failed to find the gplugin_query function in %s"),
filename);
+ Py_DECREF(module);
pyg_gil_state_release(state);
return NULL;
@@ -110,6 +115,7 @@
"function"),
filename);
+ Py_DECREF(module);
pyg_gil_state_release(state);
return NULL;
@@ -120,6 +126,7 @@
g_warning(_("Failed to find the gplugin_load function in %s"),
filename);
+ Py_DECREF(module);
pyg_gil_state_release(state);
return NULL;
@@ -129,6 +136,7 @@
"function"),
filename);
+ Py_DECREF(module);
pyg_gil_state_release(state);
return NULL;
@@ -139,6 +147,7 @@
g_warning(_("Failed to find the gplugin_unload function in %s"),
filename);
+ Py_DECREF(module);
pyg_gil_state_release(state);
return NULL;
@@ -148,6 +157,7 @@
"function"),
filename);
+ Py_DECREF(module);
pyg_gil_state_release(state);
return NULL;
@@ -172,6 +182,9 @@
"unload-func", unload,
NULL);
+ Py_DECREF(pyinfo);
+ Py_DECREF(module);
+
/* unlock the gil */
pyg_gil_state_release(state);
@@ -193,10 +206,14 @@
result = PyObject_CallFunctionObjArgs(load, pyplugin, NULL);
Py_DECREF(pyplugin);
- if(error) {
- *error = gplugin_python_exception_to_gerror();
- if(*error)
- return FALSE;
+ if (PyErr_Occurred()) {
+ Py_XDECREF(result);
+
+ if (error) {
+ *error = gplugin_python_exception_to_gerror();
+ }
+
+ return FALSE;
}
ret = PyObject_IsTrue(result);
@@ -228,7 +245,7 @@
if(PyErr_Occurred()) {
PyErr_Print();
- Py_DECREF(result);
+ Py_XDECREF(result);
return FALSE;
}
@@ -255,6 +272,7 @@
PyErr_Fetch(&type, &value, &tb);
Py_DECREF(type);
+ Py_XDECREF(tb);
obj = PyUnicode_AsUTF8String(value);
Py_DECREF(value);
@@ -277,7 +295,7 @@
static gboolean
gplugin_python_loader_init_gettext(void) {
PyObject *module_dict = NULL, *install = NULL;
- PyObject *gettext = NULL, *gettext_args = NULL;
+ PyObject *gettext = NULL, *result = NULL;
gettext = PyImport_ImportModule("gettext");
if(gettext == NULL) {
@@ -288,9 +306,9 @@
module_dict = PyModule_GetDict(gettext);
install = PyDict_GetItemString(module_dict, "install");
- gettext_args = Py_BuildValue("ss", GETTEXT_PACKAGE, LOCALEDIR);
- PyObject_CallObject(install, gettext_args);
- Py_DECREF(gettext_args);
+ result = PyObject_CallFunction(install, "ss", GETTEXT_PACKAGE, LOCALEDIR);
+ Py_XDECREF(result);
+ Py_DECREF(gettext);
return TRUE;
}
--- a/python/gplugin-python-test-pygobject.c Fri Feb 01 02:23:51 2019 +0000
+++ b/python/gplugin-python-test-pygobject.c Sat Feb 02 07:37:10 2019 +0000
@@ -39,8 +39,10 @@
wargv[0] = g_new0(wchar_t, len + 1);
len = mbstowcs(wargv[0], argv[0], len + 1);
- if(len == (size_t)-1)
+ if(len == (size_t)-1) {
+ g_free(wargv[0]);
return -1;
+ }
/* setup sys.path */
#if PY_VERSION_HEX < 0x03010300