mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Cleanup and mem leak fix
Improve usage of `gchar` and `char` by setting them correctly Increase usage of `auto_gchar` and `auto_char` Fix 2 mem leaks (rosterwin.c, avatar.c)
This commit is contained in:
parent
9451ea7c4c
commit
3a4cd7da48
@ -406,7 +406,7 @@ _get_log_filename(const char* const other, const char* const login, GDateTime* d
|
|||||||
{
|
{
|
||||||
auto_gchar gchar* chatlogs_dir = files_file_in_account_data_path(DIR_CHATLOGS, login, is_room ? "rooms" : NULL);
|
auto_gchar gchar* chatlogs_dir = files_file_in_account_data_path(DIR_CHATLOGS, login, is_room ? "rooms" : NULL);
|
||||||
auto_gchar gchar* logfile_name = g_date_time_format(dt, "%Y_%m_%d.log");
|
auto_gchar gchar* logfile_name = g_date_time_format(dt, "%Y_%m_%d.log");
|
||||||
auto_gchar gchar* other_ = str_replace(other, "@", "_at_");
|
auto_char char* other_ = str_replace(other, "@", "_at_");
|
||||||
auto_gchar gchar* logs_path = g_strdup_printf("%s/%s", chatlogs_dir, other_);
|
auto_gchar gchar* logs_path = g_strdup_printf("%s/%s", chatlogs_dir, other_);
|
||||||
gchar* logfile_path = NULL;
|
gchar* logfile_path = NULL;
|
||||||
|
|
||||||
|
@ -9270,15 +9270,15 @@ gboolean
|
|||||||
cmd_stamp(ProfWin* window, const char* const command, gchar** args)
|
cmd_stamp(ProfWin* window, const char* const command, gchar** args)
|
||||||
{
|
{
|
||||||
if (g_strv_length(args) == 0) {
|
if (g_strv_length(args) == 0) {
|
||||||
auto_gchar gchar* def = prefs_get_string(PREF_OUTGOING_STAMP);
|
auto_gchar gchar* def_incoming = prefs_get_string(PREF_OUTGOING_STAMP);
|
||||||
if (def) {
|
if (def_incoming) {
|
||||||
cons_show("The outgoing stamp is: %s", def);
|
cons_show("The outgoing stamp is: %s", def_incoming);
|
||||||
} else {
|
} else {
|
||||||
cons_show("The default outgoing stamp is used.");
|
cons_show("The default outgoing stamp is used.");
|
||||||
}
|
}
|
||||||
def = prefs_get_string(PREF_INCOMING_STAMP);
|
auto_gchar gchar* def_outgoing = prefs_get_string(PREF_INCOMING_STAMP);
|
||||||
if (def) {
|
if (def_outgoing) {
|
||||||
cons_show("The incoming stamp is: %s", def);
|
cons_show("The incoming stamp is: %s", def_outgoing);
|
||||||
} else {
|
} else {
|
||||||
cons_show("The default incoming stamp is used.");
|
cons_show("The default incoming stamp is used.");
|
||||||
}
|
}
|
||||||
@ -9687,12 +9687,11 @@ _cmd_executable_template(const preference_t setting, const char* command, gchar*
|
|||||||
|
|
||||||
} else if (g_strcmp0(args[1], "default") == 0) {
|
} else if (g_strcmp0(args[1], "default") == 0) {
|
||||||
prefs_set_string(setting, NULL);
|
prefs_set_string(setting, NULL);
|
||||||
gchar* def = prefs_get_string(setting);
|
auto_gchar gchar* def = prefs_get_string(setting);
|
||||||
if (def == NULL) {
|
if (def == NULL) {
|
||||||
def = g_strdup("built-in method");
|
def = g_strdup("built-in method");
|
||||||
}
|
}
|
||||||
cons_show("`%s` command set to invoke %s (default)", command, def);
|
cons_show("`%s` command set to invoke %s (default)", command, def);
|
||||||
g_free(def);
|
|
||||||
} else {
|
} else {
|
||||||
cons_bad_cmd_usage(command);
|
cons_bad_cmd_usage(command);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ gchar*
|
|||||||
files_get_account_data_path(const char* const specific_dir, const char* const jid)
|
files_get_account_data_path(const char* const specific_dir, const char* const jid)
|
||||||
{
|
{
|
||||||
auto_gchar gchar* data_dir = files_get_data_path(specific_dir);
|
auto_gchar gchar* data_dir = files_get_data_path(specific_dir);
|
||||||
auto_gchar gchar* account_dir = str_replace(jid, "@", "_at_");
|
auto_char char* account_dir = str_replace(jid, "@", "_at_");
|
||||||
|
|
||||||
return g_strdup_printf("%s/%s", data_dir, account_dir);
|
return g_strdup_printf("%s/%s", data_dir, account_dir);
|
||||||
}
|
}
|
||||||
|
@ -541,13 +541,13 @@ prefs_get_string(preference_t pref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
prefs_get_string_with_option(preference_t pref, gchar* option)
|
prefs_get_string_with_locale(preference_t pref, gchar* locale)
|
||||||
{
|
{
|
||||||
const char* group = _get_group(pref);
|
const char* group = _get_group(pref);
|
||||||
const char* key = _get_key(pref);
|
const char* key = _get_key(pref);
|
||||||
char* def = _get_default_string(pref);
|
char* def = _get_default_string(pref);
|
||||||
|
|
||||||
gchar* result = g_key_file_get_locale_string(prefs, group, key, option, NULL);
|
gchar* result = g_key_file_get_locale_string(prefs, group, key, locale, NULL);
|
||||||
|
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
// check for user set default
|
// check for user set default
|
||||||
@ -566,14 +566,14 @@ prefs_get_string_with_option(preference_t pref, gchar* option)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
prefs_set_string(preference_t pref, char* value)
|
prefs_set_string(preference_t pref, gchar* new_value)
|
||||||
{
|
{
|
||||||
const char* group = _get_group(pref);
|
const char* group = _get_group(pref);
|
||||||
const char* key = _get_key(pref);
|
const char* key = _get_key(pref);
|
||||||
if (value == NULL) {
|
if (new_value == NULL) {
|
||||||
g_key_file_remove_key(prefs, group, key, NULL);
|
g_key_file_remove_key(prefs, group, key, NULL);
|
||||||
} else {
|
} else {
|
||||||
g_key_file_set_string(prefs, group, key, value);
|
g_key_file_set_string(prefs, group, key, new_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,8 +336,8 @@ void prefs_save_win_placement(ProfWinPlacement* placement);
|
|||||||
gboolean prefs_get_boolean(preference_t pref);
|
gboolean prefs_get_boolean(preference_t pref);
|
||||||
void prefs_set_boolean(preference_t pref, gboolean value);
|
void prefs_set_boolean(preference_t pref, gboolean value);
|
||||||
gchar* prefs_get_string(preference_t pref);
|
gchar* prefs_get_string(preference_t pref);
|
||||||
gchar* prefs_get_string_with_option(preference_t pref, gchar* option);
|
gchar* prefs_get_string_with_locale(preference_t pref, gchar* locale);
|
||||||
void prefs_set_string(preference_t pref, char* value);
|
void prefs_set_string(preference_t pref, gchar* new_value);
|
||||||
void prefs_set_string_with_option(preference_t pref, char* option, char* value);
|
void prefs_set_string_with_option(preference_t pref, char* option, char* value);
|
||||||
void prefs_set_string_list_with_option(preference_t pref, char* option, const gchar* const* values);
|
void prefs_set_string_list_with_option(preference_t pref, char* option, const gchar* const* values);
|
||||||
|
|
||||||
|
@ -2198,30 +2198,25 @@ cons_correction_setting(void)
|
|||||||
void
|
void
|
||||||
cons_executable_setting(void)
|
cons_executable_setting(void)
|
||||||
{
|
{
|
||||||
gchar* avatar = prefs_get_string(PREF_AVATAR_CMD);
|
auto_gchar gchar* avatar = prefs_get_string(PREF_AVATAR_CMD);
|
||||||
cons_show("Default '/avatar open' command (/executable avatar) : %s", avatar);
|
cons_show("Default '/avatar open' command (/executable avatar) : %s", avatar);
|
||||||
g_free(avatar);
|
|
||||||
|
|
||||||
// TODO: there needs to be a way to get all the "locales"/schemes so we can
|
// TODO: there needs to be a way to get all the "locales"/schemes so we can
|
||||||
// display the default openers for all filetypes
|
// display the default openers for all filetypes
|
||||||
gchar* urlopen = prefs_get_string(PREF_URL_OPEN_CMD);
|
auto_gchar gchar* urlopen = prefs_get_string(PREF_URL_OPEN_CMD);
|
||||||
cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen);
|
cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen);
|
||||||
g_free(urlopen);
|
|
||||||
|
|
||||||
gchar* urlsave = prefs_get_string(PREF_URL_SAVE_CMD);
|
auto_gchar gchar* urlsave = prefs_get_string(PREF_URL_SAVE_CMD);
|
||||||
if (urlsave == NULL) {
|
if (urlsave == NULL) {
|
||||||
urlsave = g_strdup("(built-in)");
|
urlsave = g_strdup("(built-in)");
|
||||||
}
|
}
|
||||||
cons_show("Default '/url save' command (/executable urlsave) : %s", urlsave);
|
cons_show("Default '/url save' command (/executable urlsave) : %s", urlsave);
|
||||||
g_free(urlsave);
|
|
||||||
|
|
||||||
gchar* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
|
auto_gchar gchar* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
|
||||||
cons_show("Default '/editor' command (/executable editor) : %s", editor);
|
cons_show("Default '/editor' command (/executable editor) : %s", editor);
|
||||||
g_free(editor);
|
|
||||||
|
|
||||||
gchar* vcard_cmd = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
auto_gchar gchar* vcard_cmd = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||||
cons_show("Default '/vcard photo open' command (/executable vcard_photo) : %s", vcard_cmd);
|
cons_show("Default '/vcard photo open' command (/executable vcard_photo) : %s", vcard_cmd);
|
||||||
g_free(vcard_cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -830,8 +830,8 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
|
auto_gchar gchar* unreadpos2 = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
|
||||||
if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
|
if ((g_strcmp0(unreadpos2, "before") == 0) && privwin->unread > 0) {
|
||||||
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
|
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,7 +843,7 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
|
|||||||
char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1;
|
char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1;
|
||||||
g_string_append(privmsg, nick);
|
g_string_append(privmsg, nick);
|
||||||
|
|
||||||
if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
|
if ((g_strcmp0(unreadpos2, "after") == 0) && privwin->unread > 0) {
|
||||||
g_string_append_printf(privmsg, " (%d)", privwin->unread);
|
g_string_append_printf(privmsg, " (%d)", privwin->unread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto_gchar gchar* from = str_replace(from_attr, "@", "_at_");
|
auto_char char* from = str_replace(from_attr, "@", "_at_");
|
||||||
g_string_append(filename, from);
|
g_string_append(filename, from);
|
||||||
|
|
||||||
avatar_metadata* data = (avatar_metadata*)userdata;
|
avatar_metadata* data = (avatar_metadata*)userdata;
|
||||||
@ -345,18 +345,16 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
|
|||||||
|
|
||||||
// if we shall open it
|
// if we shall open it
|
||||||
if (g_hash_table_contains(shall_open, from_attr)) {
|
if (g_hash_table_contains(shall_open, from_attr)) {
|
||||||
gchar* cmdtemplate = prefs_get_string(PREF_AVATAR_CMD);
|
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_AVATAR_CMD);
|
||||||
|
|
||||||
if (cmdtemplate == NULL) {
|
if (cmdtemplate == NULL) {
|
||||||
cons_show_error("No default `avatar open` command found in executables preferences.");
|
cons_show_error("No default `avatar open` command found in executables preferences.");
|
||||||
} else {
|
} else {
|
||||||
gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
|
auto_gcharv gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
|
||||||
|
|
||||||
if (!call_external(argv)) {
|
if (!call_external(argv)) {
|
||||||
cons_show_error("Unable to display avatar: check the logs for more information.");
|
cons_show_error("Unable to display avatar: check the logs for more information.");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev(argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_remove(shall_open, from_attr);
|
g_hash_table_remove(shall_open, from_attr);
|
||||||
|
@ -1322,12 +1322,10 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
|||||||
g_string_free(filename, TRUE);
|
g_string_free(filename, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gchar* from1 = str_replace(from, "@", "_at_");
|
auto_char char* from1 = str_replace(from, "@", "_at_");
|
||||||
gchar* from2 = str_replace(from1, "/", "_slash_");
|
auto_char char* from2 = str_replace(from1, "/", "_slash_");
|
||||||
g_free(from1);
|
|
||||||
|
|
||||||
g_string_append(filename, from2);
|
g_string_append(filename, from2);
|
||||||
g_free(from2);
|
|
||||||
} else {
|
} else {
|
||||||
filename = g_string_new(data->filename);
|
filename = g_string_new(data->filename);
|
||||||
}
|
}
|
||||||
@ -1357,17 +1355,15 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
|||||||
gchar** argv;
|
gchar** argv;
|
||||||
gint argc;
|
gint argc;
|
||||||
|
|
||||||
gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||||
|
|
||||||
// this makes it work with filenames that contain spaces
|
// this makes it work with filenames that contain spaces
|
||||||
g_string_prepend(filename, "\"");
|
g_string_prepend(filename, "\"");
|
||||||
g_string_append(filename, "\"");
|
g_string_append(filename, "\"");
|
||||||
gchar* cmd = str_replace(cmdtemplate, "%p", filename->str);
|
auto_char char* cmd = str_replace(cmdtemplate, "%p", filename->str);
|
||||||
g_free(cmdtemplate);
|
|
||||||
|
|
||||||
if (g_shell_parse_argv(cmd, &argc, &argv, &err) == FALSE) {
|
if (g_shell_parse_argv(cmd, &argc, &argv, &err) == FALSE) {
|
||||||
cons_show_error("Failed to parse command template");
|
cons_show_error("Failed to parse command template");
|
||||||
g_free(cmd);
|
|
||||||
} else {
|
} else {
|
||||||
if (!call_external(argv)) {
|
if (!call_external(argv)) {
|
||||||
cons_show_error("Unable to execute command");
|
cons_show_error("Unable to execute command");
|
||||||
|
Loading…
Reference in New Issue
Block a user