Change char->free to auto_char char for autocleanup

Replace `gchar` and `g_free` to `auto_gchar`
Correct certain  `char` functions/variables to `gchar`

Related to #1819.

Edited by @jubalh.
This commit is contained in:
John Hernandez
2023-07-11 13:23:58 +02:00
parent 245d69deb6
commit e1d137f4e6
62 changed files with 498 additions and 969 deletions

View File

@@ -71,9 +71,8 @@ api_cons_show(const char* const message)
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
auto_char char* parsed = str_replace(message, "\r\n", "\n");
cons_show("%s", parsed);
free(parsed);
return 1;
}
@@ -86,13 +85,11 @@ api_cons_show_themed(const char* const group, const char* const key, const char*
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
auto_char char* parsed = str_replace(message, "\r\n", "\n");
theme_item_t themeitem = plugin_themes_get(group, key, def);
ProfWin* console = wins_get_console();
win_println(console, themeitem, "-", "%s", parsed);
free(parsed);
return 1;
}
@@ -798,9 +795,8 @@ api_chat_show(const char* const barejid, const char* message)
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
auto_char char* parsed = str_replace(message, "\r\n", "\n");
win_println((ProfWin*)chatwin, THEME_TEXT, "-", "%s", parsed);
free(parsed);
return 1;
}
@@ -835,11 +831,10 @@ api_chat_show_themed(const char* const barejid, const char* const group, const c
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
auto_char char* parsed = str_replace(message, "\r\n", "\n");
theme_item_t themeitem = plugin_themes_get(group, key, def);
win_println((ProfWin*)chatwin, themeitem, show_ch, "%s", parsed);
free(parsed);
return 1;
}
@@ -863,9 +858,8 @@ api_room_show(const char* const roomjid, const char* message)
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
auto_char char* parsed = str_replace(message, "\r\n", "\n");
win_println((ProfWin*)mucwin, THEME_TEXT, "-", "%s", parsed);
free(parsed);
return 1;
}
@@ -900,11 +894,10 @@ api_room_show_themed(const char* const roomjid, const char* const group, const c
return 0;
}
char* parsed = str_replace(message, "\r\n", "\n");
auto_char char* parsed = str_replace(message, "\r\n", "\n");
theme_item_t themeitem = plugin_themes_get(group, key, def);
win_println((ProfWin*)mucwin, themeitem, show_ch, "%s", parsed);
free(parsed);
return 1;
}

View File

@@ -91,72 +91,60 @@ c_api_register_command(const char* filename, const char* command_name, int min_a
char** synopsis, const char* description, char* arguments[][2], char** examples,
void (*callback)(char** args))
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Register command %s for %s", command_name, plugin_name);
CommandWrapper* wrapper = malloc(sizeof(CommandWrapper));
wrapper->func = callback;
api_register_command(plugin_name, command_name, min_args, max_args, synopsis,
description, arguments, examples, wrapper, c_command_callback, free);
free(plugin_name);
}
static void
c_api_register_timed(const char* filename, void (*callback)(void), int interval_seconds)
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Register timed for %s", plugin_name);
TimedWrapper* wrapper = malloc(sizeof(TimedWrapper));
wrapper->func = callback;
api_register_timed(plugin_name, wrapper, interval_seconds, c_timed_callback, free);
free(plugin_name);
}
static void
c_api_completer_add(const char* filename, const char* key, char** items)
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Autocomplete add %s for %s", key, plugin_name);
api_completer_add(plugin_name, key, items);
free(plugin_name);
}
static void
c_api_completer_remove(const char* filename, const char* key, char** items)
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Autocomplete remove %s for %s", key, plugin_name);
api_completer_remove(plugin_name, key, items);
free(plugin_name);
}
static void
c_api_completer_clear(const char* filename, const char* key)
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Autocomplete clear %s for %s", key, plugin_name);
api_completer_clear(plugin_name, key);
free(plugin_name);
}
static void
c_api_filepath_completer_add(const char* filename, const char* prefix)
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
log_debug("Filepath autocomplete added '%s' for %s", prefix, plugin_name);
api_filepath_completer_add(plugin_name, prefix);
free(plugin_name);
}
static void
@@ -252,13 +240,11 @@ c_api_win_exists(char* tag)
static void
c_api_win_create(const char* filename, char* tag, void (*callback)(char* tag, char* line))
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
WindowWrapper* wrapper = malloc(sizeof(WindowWrapper));
wrapper->func = callback;
api_win_create(plugin_name, tag, wrapper, c_window_callback, free);
free(plugin_name);
}
static int
@@ -354,9 +340,8 @@ c_api_incoming_message(char* barejid, char* resource, char* message)
static void
c_api_disco_add_feature(const char* filename, char* feature)
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename);
api_disco_add_feature(plugin_name, feature);
free(plugin_name);
}
static void

View File

@@ -65,9 +65,8 @@ c_plugin_create(const char* const filename)
ProfPlugin* plugin;
void* handle = NULL;
char* plugins_dir = files_get_data_path(DIR_PLUGINS);
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
GString* path = g_string_new(plugins_dir);
free(plugins_dir);
g_string_append(path, "/");
g_string_append(path, filename);

View File

@@ -172,9 +172,8 @@ gboolean
plugins_uninstall(const char* const plugin_name)
{
plugins_unload(plugin_name);
char* plugins_dir = files_get_data_path(DIR_PLUGINS);
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
GString* target_path = g_string_new(plugins_dir);
free(plugins_dir);
g_string_append(target_path, "/");
g_string_append(target_path, plugin_name);
GFile* file = g_file_new_for_path(target_path->str);
@@ -189,9 +188,8 @@ plugins_uninstall(const char* const plugin_name)
gboolean
plugins_install(const char* const plugin_name, const char* const filename, GString* error_message)
{
char* plugins_dir = files_get_data_path(DIR_PLUGINS);
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
GString* target_path = g_string_new(plugins_dir);
free(plugins_dir);
g_string_append(target_path, "/");
g_string_append(target_path, plugin_name);
@@ -387,9 +385,8 @@ GSList*
plugins_unloaded_list(void)
{
GSList* result = NULL;
char* plugins_dir = files_get_data_path(DIR_PLUGINS);
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
_plugins_unloaded_list_dir(plugins_dir, &result);
free(plugins_dir);
return result;
}

View File

@@ -99,7 +99,7 @@ python_env_init(void)
python_init_prof();
char* plugins_dir = files_get_data_path(DIR_PLUGINS);
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
GString* path = g_string_new("import sys\n");
g_string_append(path, "sys.path.append(\"");
g_string_append(path, plugins_dir);
@@ -109,7 +109,6 @@ python_env_init(void)
python_check_error();
g_string_free(path, TRUE);
g_free(plugins_dir);
allow_python_threads();
}

View File

@@ -53,7 +53,7 @@ static void _save_settings(void);
void
plugin_settings_init(void)
{
char* settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS);
auto_gchar gchar* settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS);
if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) {
g_chmod(settings_file, S_IRUSR | S_IWUSR);
@@ -63,11 +63,9 @@ plugin_settings_init(void)
g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
gsize g_data_size;
gchar* g_data = g_key_file_to_data(settings, &g_data_size, NULL);
auto_gchar gchar* g_data = g_key_file_to_data(settings, &g_data_size, NULL);
g_file_set_contents(settings_file, g_data, g_data_size, NULL);
g_chmod(settings_file, S_IRUSR | S_IWUSR);
g_free(g_data);
free(settings_file);
}
void
@@ -175,15 +173,11 @@ static void
_save_settings(void)
{
gsize g_data_size;
gchar* g_data = g_key_file_to_data(settings, &g_data_size, NULL);
auto_gchar gchar* g_data = g_key_file_to_data(settings, &g_data_size, NULL);
char* fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
gchar* base = g_path_get_dirname(fileloc);
gchar* true_loc = get_file_or_linked(fileloc, base);
g_free(base);
auto_gchar gchar* fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
auto_gchar gchar* base = g_path_get_dirname(fileloc);
auto_gchar gchar* true_loc = get_file_or_linked(fileloc, base);
g_file_set_contents(true_loc, g_data, g_data_size, NULL);
free(true_loc);
g_free(g_data);
g_chmod(fileloc, S_IRUSR | S_IWUSR);
free(fileloc);
}

View File

@@ -49,7 +49,7 @@ static GKeyFile* themes;
void
plugin_themes_init(void)
{
char* themes_file = files_get_data_path(FILE_PLUGIN_THEMES);
auto_gchar gchar* themes_file = files_get_data_path(FILE_PLUGIN_THEMES);
if (g_file_test(themes_file, G_FILE_TEST_EXISTS)) {
g_chmod(themes_file, S_IRUSR | S_IWUSR);
@@ -59,11 +59,9 @@ plugin_themes_init(void)
g_key_file_load_from_file(themes, themes_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
gsize g_data_size;
gchar* g_data = g_key_file_to_data(themes, &g_data_size, NULL);
auto_gchar gchar* g_data = g_key_file_to_data(themes, &g_data_size, NULL);
g_file_set_contents(themes_file, g_data, g_data_size, NULL);
g_chmod(themes_file, S_IRUSR | S_IWUSR);
g_free(g_data);
free(themes_file);
}
void