From 923256b8bb02917802eb0727eb1775bcd3d51d57 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 25 Jul 2016 00:18:52 +0100 Subject: [PATCH 1/2] Free icon dir path name --- src/ui/tray.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/tray.c b/src/ui/tray.c index 374eefb7..ec1f1f96 100644 --- a/src/ui/tray.c +++ b/src/ui/tray.c @@ -81,6 +81,7 @@ _get_icons(void) char *icons_dir_s = files_get_config_path(DIR_ICONS); icons_dir = g_string_new(icons_dir_s); + free(icons_dir_s); GError *err = NULL; if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) { return; From 8f9f018d5a2f80267783477c7f8cce8869cf5528 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 25 Jul 2016 00:41:34 +0100 Subject: [PATCH 2/2] Free python_str_or_unicode_to_string results --- src/plugins/api.c | 2 +- src/plugins/api.h | 2 +- src/plugins/c_api.c | 2 +- src/plugins/profapi.c | 2 +- src/plugins/profapi.h | 2 +- src/plugins/python_api.c | 27 +++++++++++++++++++++++---- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/plugins/api.c b/src/plugins/api.c index 8ac4856f..8011dee5 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -107,7 +107,7 @@ api_cons_bad_cmd_usage(const char *const cmd) void api_register_command(const char *const plugin_name, const char *command_name, int min_args, int max_args, - const char **synopsis, const char *description, const char *arguments[][2], const char **examples, + char **synopsis, const char *description, char *arguments[][2], char **examples, void *callback, void(*callback_exec)(PluginCommand *command, gchar **args), void(*callback_destroy)(void *callback)) { PluginCommand *command = malloc(sizeof(PluginCommand)); diff --git a/src/plugins/api.h b/src/plugins/api.h index db1417cf..5886dae2 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -51,7 +51,7 @@ char* api_get_current_nick(void); char** api_get_current_occupants(void); void api_register_command(const char *const plugin_name, const char *command_name, int min_args, int max_args, - const char **synopsis, const char *description, const char *arguments[][2], const char **examples, + char **synopsis, const char *description, char *arguments[][2], char **examples, void *callback, void(*callback_func)(PluginCommand *command, gchar **args), void(*callback_destroy)(void *callback)); void api_register_timed(const char *const plugin_name, void *callback, int interval_seconds, void (*callback_func)(PluginTimedFunction *timed_function), void(*callback_destroy)(void *callback)); diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 67116d31..042010db 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -82,7 +82,7 @@ c_api_cons_bad_cmd_usage(const char *const cmd) static void c_api_register_command(const char *filename, const char *command_name, int min_args, int max_args, - const char **synopsis, const char *description, const char *arguments[][2], const char **examples, + char **synopsis, const char *description, char *arguments[][2], char **examples, void(*callback)(char **args)) { char *plugin_name = _c_plugin_name(filename); diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index bbe570df..e5f46cb4 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -43,7 +43,7 @@ int (*prof_cons_show_themed)(const char *const group, const char *const item, co int (*prof_cons_bad_cmd_usage)(const char *const cmd) = NULL; void (*_prof_register_command)(const char *filename, const char *command_name, int min_args, int max_args, - const char **synopsis, const char *description, const char *arguments[][2], const char **examples, + char **synopsis, const char *description, char *arguments[][2], char **examples, void(*callback)(char **args)) = NULL; void (*_prof_register_timed)(const char *filename, void(*callback)(void), int interval_seconds) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 1e2e8b01..c75b8f03 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -50,7 +50,7 @@ int (*prof_cons_show_themed)(const char *const group, const char *const item, co int (*prof_cons_bad_cmd_usage)(const char *const cmd); void (*_prof_register_command)(const char *filename, const char *command_name, int min_args, int max_args, - const char **synopsis, const char *description, const char *arguments[][2], const char **examples, + char **synopsis, const char *description, char *arguments[][2], char **examples, void(*callback)(char **args)); void (*_prof_register_timed)(const char *filename, void(*callback)(void), int interval_seconds); diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index c5a1ef80..08611d33 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -148,7 +148,7 @@ python_api_register_command(PyObject *self, PyObject *args) if (p_callback && PyCallable_Check(p_callback)) { Py_ssize_t len = PyList_Size(synopsis); - const char *c_synopsis[len == 0 ? 0 : len+1]; + char *c_synopsis[len == 0 ? 0 : len+1]; Py_ssize_t i = 0; for (i = 0; i < len; i++) { PyObject *item = PyList_GetItem(synopsis, i); @@ -158,7 +158,7 @@ python_api_register_command(PyObject *self, PyObject *args) c_synopsis[len] = NULL; Py_ssize_t args_len = PyList_Size(arguments); - const char *c_arguments[args_len == 0 ? 0 : args_len+1][2]; + char *c_arguments[args_len == 0 ? 0 : args_len+1][2]; i = 0; for (i = 0; i < args_len; i++) { PyObject *item = PyList_GetItem(arguments, i); @@ -179,7 +179,7 @@ python_api_register_command(PyObject *self, PyObject *args) c_arguments[args_len][1] = NULL; len = PyList_Size(examples); - const char *c_examples[len == 0 ? 0 : len+1]; + char *c_examples[len == 0 ? 0 : len+1]; i = 0; for (i = 0; i < len; i++) { PyObject *item = PyList_GetItem(examples, i); @@ -193,6 +193,20 @@ python_api_register_command(PyObject *self, PyObject *args) description_str, c_arguments, c_examples, p_callback, python_command_callback, NULL); free(command_name_str); free(description_str); + i = 0; + while (c_synopsis[i] != NULL) { + free(c_synopsis[i++]); + } + i = 0; + while (c_arguments[i] != NULL && c_arguments[i][0] != NULL) { + free(c_arguments[i][0]); + free(c_arguments[i][1]); + i++; + } + i = 0; + while (c_examples[i] != NULL) { + free(c_examples[i++]); + } disable_python_threads(); } @@ -254,6 +268,10 @@ python_api_completer_add(PyObject *self, PyObject *args) allow_python_threads(); api_completer_add(plugin_name, key_str, c_items); free(key_str); + i = 0; + while (c_items[i] != NULL) { + free(c_items[i++]); + } disable_python_threads(); free(plugin_name); @@ -993,8 +1011,9 @@ _python_plugin_name(void) { PyThreadState *ts = PyThreadState_Get(); PyFrameObject *frame = ts->frame; - char const* filename = python_str_or_unicode_to_string(frame->f_code->co_filename); + char* filename = python_str_or_unicode_to_string(frame->f_code->co_filename); gchar **split = g_strsplit(filename, "/", 0); + free(filename); char *plugin_name = strdup(split[g_strv_length(split)-1]); g_strfreev(split);