diff --git a/src/chatlog.c b/src/chatlog.c index 513af0b4..738ccc90 100644 --- a/src/chatlog.c +++ b/src/chatlog.c @@ -85,9 +85,8 @@ void chat_log_msg_out(const char* const barejid, const char* const msg, const char* const resource) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); _chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); - free(mybarejid); } } @@ -95,14 +94,13 @@ void chat_log_otr_msg_out(const char* const barejid, const char* const msg, const char* const resource) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG); if (strcmp(pref_otr_log, "on") == 0) { _chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); } else if (strcmp(pref_otr_log, "redact") == 0) { _chat_log_chat(mybarejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource); } - free(mybarejid); } } @@ -110,14 +108,13 @@ void chat_log_pgp_msg_out(const char* const barejid, const char* const msg, const char* const resource) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_pgp_log = prefs_get_string(PREF_PGP_LOG); if (strcmp(pref_pgp_log, "on") == 0) { _chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); } else if (strcmp(pref_pgp_log, "redact") == 0) { _chat_log_chat(mybarejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource); } - free(mybarejid); } } @@ -125,14 +122,13 @@ void chat_log_omemo_msg_out(const char* const barejid, const char* const msg, const char* const resource) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG); if (strcmp(pref_omemo_log, "on") == 0) { _chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); } else if (strcmp(pref_omemo_log, "redact") == 0) { _chat_log_chat(mybarejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource); } - free(mybarejid); } } @@ -140,7 +136,7 @@ void chat_log_otr_msg_in(ProfMessage* message) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG); if (message->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) { if (message->type == PROF_MSG_TYPE_MUCPM) { @@ -155,7 +151,6 @@ chat_log_otr_msg_in(ProfMessage* message) _chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL); } } - free(mybarejid); } } @@ -163,7 +158,7 @@ void chat_log_pgp_msg_in(ProfMessage* message) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_pgp_log = prefs_get_string(PREF_PGP_LOG); if (strcmp(pref_pgp_log, "on") == 0) { if (message->type == PROF_MSG_TYPE_MUCPM) { @@ -178,7 +173,6 @@ chat_log_pgp_msg_in(ProfMessage* message) _chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL); } } - free(mybarejid); } } @@ -186,7 +180,7 @@ void chat_log_omemo_msg_in(ProfMessage* message) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG); if (strcmp(pref_omemo_log, "on") == 0) { if (message->type == PROF_MSG_TYPE_MUCPM) { @@ -201,7 +195,6 @@ chat_log_omemo_msg_in(ProfMessage* message) _chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart); } } - free(mybarejid); } } @@ -209,15 +202,13 @@ void chat_log_msg_in(ProfMessage* message) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); if (message->type == PROF_MSG_TYPE_MUCPM) { _chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart); } else { _chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL); } - - free(mybarejid); } } @@ -317,10 +308,9 @@ void groupchat_log_msg_out(const gchar* const room, const gchar* const msg) { if (prefs_get_boolean(PREF_GRLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); char* mynick = muc_nick(room); _groupchat_log_chat(mybarejid, room, mynick, msg); - free(mybarejid); } } @@ -328,9 +318,8 @@ void groupchat_log_msg_in(const gchar* const room, const gchar* const nick, const gchar* const msg) { if (prefs_get_boolean(PREF_GRLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); _groupchat_log_chat(mybarejid, room, nick, msg); - free(mybarejid); } } @@ -338,7 +327,7 @@ void groupchat_log_omemo_msg_out(const gchar* const room, const gchar* const msg) { if (prefs_get_boolean(PREF_CHLOG)) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG); char* mynick = muc_nick(room); @@ -347,8 +336,6 @@ groupchat_log_omemo_msg_out(const gchar* const room, const gchar* const msg) } else if (strcmp(pref_omemo_log, "redact") == 0) { _groupchat_log_chat(mybarejid, room, mynick, "[redacted]"); } - - free(mybarejid); } } @@ -434,14 +421,12 @@ static struct dated_chat_log* _create_chatlog(const char* const other, const char* const login) { GDateTime* now = g_date_time_new_now_local(); - char* filename = _get_log_filename(other, login, now, FALSE); + auto_char char* filename = _get_log_filename(other, login, now, FALSE); struct dated_chat_log* new_log = malloc(sizeof(struct dated_chat_log)); new_log->filename = strdup(filename); new_log->date = now; - free(filename); - return new_log; } @@ -449,14 +434,12 @@ static struct dated_chat_log* _create_groupchat_log(const char* const room, const char* const login) { GDateTime* now = g_date_time_new_now_local(); - char* filename = _get_log_filename(room, login, now, TRUE); + auto_char char* filename = _get_log_filename(room, login, now, TRUE); struct dated_chat_log* new_log = malloc(sizeof(struct dated_chat_log)); new_log->filename = strdup(filename); new_log->date = now; - free(filename); - return new_log; } diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index afcee642..d5b779c0 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -3052,13 +3052,12 @@ command_mangen(void) while (curr) { Command* pcmd = curr->data; - gchar* filename = g_strdup_printf("docs/profanity-%s.1", &pcmd->cmd[1]); + auto_gchar gchar* filename = g_strdup_printf("docs/profanity-%s.1", &pcmd->cmd[1]); if (!filename) { log_error("command_mangen(): could not allocate memory"); return; } FILE* manpage = fopen(filename, "w"); - free(filename); fprintf(manpage, "%s\n", header); fputs(".SH NAME\n", manpage); diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 7c80995b..848da549 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -188,44 +188,41 @@ _string_matches_one_of(const char* what, const char* is, bool is_can_be_null, co return ret; } -/* - * Take a line of input and process it, return TRUE if profanity is to - * continue, FALSE otherwise +/** + * @brief Processes a line of input and determines if profanity should continue. + * + * @param window + * @param inp The input string to process. + * @return Returns TRUE if profanity is to continue, FALSE otherwise. */ gboolean cmd_process_input(ProfWin* window, char* inp) { log_debug("Input received: %s", inp); - gboolean result = FALSE; g_strchomp(inp); - // just carry on if no input if (strlen(inp) == 0) { - result = TRUE; + return TRUE; + } - // handle command if input starts with a '/' - } else if (inp[0] == '/') { - char* inp_cpy = strdup(inp); + // handle command if input starts with a '/' + if (inp[0] == '/') { + auto_char char* inp_cpy = strdup(inp); char* command = strtok(inp_cpy, " "); char* question_mark = strchr(command, '?'); if (question_mark) { *question_mark = '\0'; - gchar* fakeinp = g_strdup_printf("/help %s", command + 1); + auto_gchar gchar* fakeinp = g_strdup_printf("/help %s", command + 1); if (fakeinp) { - result = _cmd_execute(window, "/help", fakeinp); - g_free(fakeinp); + return _cmd_execute(window, "/help", fakeinp); } } else { - result = _cmd_execute(window, command, inp); + return _cmd_execute(window, command, inp); } - free(inp_cpy); - - // call a default handler if input didn't start with '/' - } else { - result = _cmd_execute_default(window, inp); } - return result; + // call a default handler if input didn't start with '/' + return _cmd_execute_default(window, inp); } // Command execution @@ -264,10 +261,9 @@ cmd_tls_certpath(ProfWin* window, const char* const command, gchar** args) cons_show("Certificate path defaulted to finding system certpath."); return TRUE; } else if (args[1] == NULL) { - char* path = prefs_get_tls_certpath(); + auto_char char* path = prefs_get_tls_certpath(); if (path) { cons_show("Trusted certificate path: %s", path); - free(path); } else { cons_show("No trusted certificate path set."); } @@ -420,24 +416,23 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args) int port = 0; if (g_hash_table_contains(options, "port")) { char* port_str = g_hash_table_lookup(options, "port"); - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); - free(err_msg); port = 0; options_destroy(options); return TRUE; } } - char* user = args[0]; + gchar* user_orig = args[0]; auto_gchar gchar* def = prefs_get_string(PREF_DEFAULT_ACCOUNT); - if (!user) { + if (!user_orig) { if (def) { - user = def; - cons_show("Using default account %s.", user); + user_orig = def; + cons_show("Using default account %s.", user_orig); } else { cons_show("No default account."); options_destroy(options); @@ -445,8 +440,8 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args) } } - char* jid; - user = strdup(user); + auto_char char* jid = NULL; + auto_char char* user = strdup(user_orig); // connect with account ProfAccount* account = accounts_get_account(user); @@ -475,7 +470,6 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args) } else { cons_show("Error evaluating password, see logs for details."); account_free(account); - free(user); options_destroy(options); return TRUE; } @@ -494,9 +488,8 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args) // connect with JID } else { jid = g_utf8_strdown(user, -1); - char* passwd = ui_ask_password(false); + auto_char char* passwd = ui_ask_password(false); conn_status = cl_ev_connect_jid(jid, passwd, altdomain, port, tls_policy, auth_policy); - free(passwd); } if (conn_status == JABBER_DISCONNECTED) { @@ -505,8 +498,6 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args) } options_destroy(options); - free(jid); - free(user); return TRUE; } @@ -524,7 +515,7 @@ cmd_account_list(ProfWin* window, const char* const command, gchar** args) gboolean cmd_account_show(ProfWin* window, const char* const command, gchar** args) { - char* account_name = args[1]; + gchar* account_name = args[1]; if (account_name == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -545,7 +536,7 @@ cmd_account_show(ProfWin* window, const char* const command, gchar** args) gboolean cmd_account_add(ProfWin* window, const char* const command, gchar** args) { - char* account_name = args[1]; + gchar* account_name = args[1]; if (account_name == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -561,7 +552,7 @@ cmd_account_add(ProfWin* window, const char* const command, gchar** args) gboolean cmd_account_remove(ProfWin* window, const char* const command, gchar** args) { - char* account_name = args[1]; + gchar* account_name = args[1]; if (!account_name) { cons_bad_cmd_usage(command); return TRUE; @@ -586,7 +577,7 @@ cmd_account_remove(ProfWin* window, const char* const command, gchar** args) gboolean cmd_account_enable(ProfWin* window, const char* const command, gchar** args) { - char* account_name = args[1]; + gchar* account_name = args[1]; if (account_name == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -605,7 +596,7 @@ cmd_account_enable(ProfWin* window, const char* const command, gchar** args) gboolean cmd_account_disable(ProfWin* window, const char* const command, gchar** args) { - char* account_name = args[1]; + gchar* account_name = args[1]; if (account_name == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -630,8 +621,8 @@ cmd_account_rename(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* account_name = args[1]; - char* new_name = args[2]; + gchar* account_name = args[1]; + gchar* new_name = args[2]; if (accounts_rename(account_name, new_name)) { cons_show("Account renamed."); @@ -714,12 +705,11 @@ gboolean _account_set_port(char* account_name, char* port) { int porti; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(port, &porti, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); - free(err_msg); } else { accounts_set_port(account_name, porti); cons_show("Updated port for account %s: %s", account_name, port); @@ -817,14 +807,13 @@ gboolean _account_set_pgpkeyid(char* account_name, char* pgpkeyid) { #ifdef HAVE_LIBGPGME - char* err_str = NULL; + auto_char char* err_str = NULL; if (!p_gpg_valid_key(pgpkeyid, &err_str)) { cons_show("Invalid PGP key ID specified: %s, see /pgp keys", err_str); } else { accounts_set_pgp_keyid(account_name, pgpkeyid); cons_show("Updated PGP key ID for account %s: %s", account_name, pgpkeyid); } - free(err_str); #else cons_show("PGP support is not included in this build."); #endif @@ -908,12 +897,11 @@ gboolean _account_set_max_sessions(char* account_name, char* max_sessions_raw) { int max_sessions; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(max_sessions_raw, &max_sessions, 0, INT_MAX, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); - free(err_msg); return TRUE; } accounts_set_max_sessions(account_name, max_sessions); @@ -930,11 +918,10 @@ gboolean _account_set_presence_priority(char* account_name, char* presence, char* priority) { int intval; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(priority, &intval, -128, 127, &err_msg); if (!res) { cons_show(err_msg); - free(err_msg); return TRUE; } @@ -978,15 +965,15 @@ cmd_account_set(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* account_name = args[1]; + gchar* account_name = args[1]; if (!accounts_account_exists(account_name)) { cons_show("Account %s doesn't exist", account_name); cons_show(""); return TRUE; } - char* property = args[2]; - char* value = args[3]; + gchar* property = args[2]; + gchar* value = args[3]; if (strcmp(property, "jid") == 0) return _account_set_jid(account_name, value); if (strcmp(property, "server") == 0) @@ -1040,14 +1027,14 @@ cmd_account_clear(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* account_name = args[1]; + gchar* account_name = args[1]; if (!accounts_account_exists(account_name)) { cons_show("Account %s doesn't exist", account_name); cons_show(""); return TRUE; } - char* property = args[2]; + gchar* property = args[2]; if (strcmp(property, "password") == 0) { accounts_clear_password(account_name); cons_show("Removed password for account %s", account_name); @@ -1146,7 +1133,8 @@ _writecsv(int fd, const char* const str) if (!str) return 0; size_t len = strlen(str); - char* s = malloc(2 * len * sizeof(char)); + + auto_char char* s = malloc(2 * len * sizeof(char)); char* c = s; for (int i = 0; i < strlen(str); i++) { if (str[i] != '"') @@ -1161,7 +1149,6 @@ _writecsv(int fd, const char* const str) cons_show("error: failed to write '%s' to the requested file: %s", s, strerror(errno)); return -1; } - free(s); return 0; } @@ -1177,10 +1164,9 @@ cmd_export(ProfWin* window, const char* const command, gchar** args) } else { int fd; GSList* list = NULL; - char* path = get_expanded_path(args[0]); + auto_char char* path = get_expanded_path(args[0]); fd = open(path, O_WRONLY | O_CREAT, 00600); - free(path); if (-1 == fd) { cons_show("error: cannot open %s: %s", args[0], strerror(errno)); @@ -1705,8 +1691,8 @@ cmd_help(ProfWin* window, const char* const command, gchar** args) } else if (strcmp(args[0], "navigation") == 0) { cons_navigation_help(); } else { - char* cmd = args[0]; - char* cmd_with_slash = g_strdup_printf("/%s", cmd); + gchar* cmd = args[0]; + auto_gchar gchar* cmd_with_slash = g_strdup_printf("/%s", cmd); Command* command = cmd_get(cmd_with_slash); if (command) { @@ -1720,7 +1706,6 @@ cmd_help(ProfWin* window, const char* const command, gchar** args) } } cons_show(""); - g_free(cmd_with_slash); } return TRUE; @@ -1854,7 +1839,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args) // presence filter if (_string_matches_one_of(NULL, args[0], TRUE, "online", "available", "unavailable", "away", "chat", "xa", "dnd", "any", NULL)) { - char* presence = args[0]; + gchar* presence = args[0]; GList* occupants = muc_roster(mucwin->roomjid); // no arg, show all contacts @@ -1948,7 +1933,7 @@ _who_room(ProfWin* window, const char* const command, gchar** args) static void _who_roster(ProfWin* window, const char* const command, gchar** args) { - char* presence = args[0]; + gchar* presence = args[0]; // bad arg if (!_string_matches_one_of(NULL, presence, TRUE, "online", "available", "unavailable", "offline", "away", "chat", "xa", "dnd", "any", NULL)) { @@ -2199,8 +2184,8 @@ _cmd_msg_chatwin(const char* const barejid, const char* const msg) gboolean cmd_msg(ProfWin* window, const char* const command, gchar** args) { - char* usr = args[0]; - char* msg = args[1]; + gchar* usr = args[0]; + gchar* msg = args[1]; jabber_conn_status_t conn_status = connection_get_status(); @@ -2293,7 +2278,7 @@ cmd_group(ProfWin* window, const char* const command, gchar** args) // show contacts in group if (strcmp(args[1], "show") == 0) { - char* group = args[2]; + gchar* group = args[2]; if (group == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -2306,8 +2291,8 @@ cmd_group(ProfWin* window, const char* const command, gchar** args) // add contact to group if (strcmp(args[1], "add") == 0) { - char* group = args[2]; - char* contact = args[3]; + gchar* group = args[2]; + gchar* contact = args[3]; if ((group == NULL) || (contact == NULL)) { cons_bad_cmd_usage(command); @@ -2337,8 +2322,8 @@ cmd_group(ProfWin* window, const char* const command, gchar** args) // remove contact from group if (strcmp(args[1], "remove") == 0) { - char* group = args[2]; - char* contact = args[3]; + gchar* group = args[2]; + gchar* contact = args[3]; if ((group == NULL) || (contact == NULL)) { cons_bad_cmd_usage(command); @@ -2406,7 +2391,7 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) return TRUE; } int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg); if (res) { prefs_set_roster_size(intval); @@ -2417,7 +2402,6 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) return TRUE; } else { cons_show(err_msg); - free(err_msg); return TRUE; } @@ -2470,7 +2454,7 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_bad_cmd_usage(command); } else { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[2], &intval, 0, 10, &err_msg); if (res) { prefs_set_roster_contact_indent(intval); @@ -2478,7 +2462,6 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) rosterwin_roster(); } else { cons_show(err_msg); - free(err_msg); } } } else { @@ -2505,7 +2488,7 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_bad_cmd_usage(command); } else { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[2], &intval, 0, 10, &err_msg); if (res) { prefs_set_roster_resource_indent(intval); @@ -2513,7 +2496,6 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) rosterwin_roster(); } else { cons_show(err_msg); - free(err_msg); } } } else if (g_strcmp0(args[1], "join") == 0) { @@ -2532,7 +2514,7 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_bad_cmd_usage(command); } else { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[2], &intval, -1, 10, &err_msg); if (res) { prefs_set_roster_presence_indent(intval); @@ -2540,7 +2522,6 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) rosterwin_roster(); } else { cons_show(err_msg); - free(err_msg); } } } else { @@ -2934,11 +2915,11 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_show("You are not currently connected."); return TRUE; } - char* jid = args[1]; + gchar* jid = args[1]; if (jid == NULL) { cons_bad_cmd_usage(command); } else { - char* name = args[2]; + gchar* name = args[2]; roster_send_add_new(jid, name); } return TRUE; @@ -2949,7 +2930,7 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_show("You are not currently connected."); return TRUE; } - char* usr = args[1]; + gchar* usr = args[1]; if (usr == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -2987,13 +2968,13 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_show("You are not currently connected."); return TRUE; } - char* jid = args[1]; + gchar* jid = args[1]; if (jid == NULL) { cons_bad_cmd_usage(command); return TRUE; } - char* name = args[2]; + gchar* name = args[2]; if (name == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -3025,7 +3006,7 @@ cmd_roster(ProfWin* window, const char* const command, gchar** args) cons_show("You are not currently connected."); return TRUE; } - char* jid = args[1]; + gchar* jid = args[1]; if (jid == NULL) { cons_bad_cmd_usage(command); return TRUE; @@ -3072,7 +3053,7 @@ cmd_blocked(ProfWin* window, const char* const command, gchar** args) blocked_report br = BLOCKED_NO_REPORT; if (g_strcmp0(args[0], "add") == 0) { - char* jid = args[1]; + gchar* jid = args[1]; if (jid == NULL && (window->type == WIN_CHAT)) { ProfChatWin* chatwin = (ProfChatWin*)window; @@ -3161,8 +3142,8 @@ cmd_blocked(ProfWin* window, const char* const command, gchar** args) gboolean cmd_resource(ProfWin* window, const char* const command, gchar** args) { - char* cmd = args[0]; - char* setting = NULL; + gchar* cmd = args[0]; + gchar* setting = NULL; if (g_strcmp0(cmd, "message") == 0) { setting = args[1]; if (!setting) { @@ -3197,7 +3178,7 @@ cmd_resource(ProfWin* window, const char* const command, gchar** args) ProfChatWin* chatwin = (ProfChatWin*)window; if (g_strcmp0(cmd, "set") == 0) { - char* resource = args[1]; + gchar* resource = args[1]; if (!resource) { cons_bad_cmd_usage(command); return TRUE; @@ -3252,7 +3233,7 @@ _cmd_status_show_status(char* usr) gboolean cmd_status_set(ProfWin* window, const char* const command, gchar** args) { - char* state = args[1]; + gchar* state = args[1]; if (g_strcmp0(state, "online") == 0) { _update_presence(RESOURCE_ONLINE, "online", args); @@ -3274,7 +3255,7 @@ cmd_status_set(ProfWin* window, const char* const command, gchar** args) gboolean cmd_status_get(ProfWin* window, const char* const command, gchar** args) { - char* usr = args[1]; + gchar* usr = args[1]; jabber_conn_status_t conn_status = connection_get_status(); @@ -3360,7 +3341,7 @@ _cmd_info_show_contact(char* usr) gboolean cmd_info(ProfWin* window, const char* const command, gchar** args) { - char* usr = args[0]; + gchar* usr = args[0]; jabber_conn_status_t conn_status = connection_get_status(); @@ -3509,7 +3490,7 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args) static void _send_software_version_iq_to_fulljid(char* request) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); Jid* jid = jid_create(request); if (jid == NULL || jid->fulljid == NULL) { @@ -3519,7 +3500,6 @@ _send_software_version_iq_to_fulljid(char* request) } else { iq_send_software_version(jid->fulljid); } - free(mybarejid); jid_destroy(jid); } @@ -3731,8 +3711,8 @@ cmd_invite(ProfWin* window, const char* const command, gchar** args) } if (g_strcmp0(args[0], "send") == 0) { - char* contact = args[1]; - char* reason = args[2]; + gchar* contact = args[1]; + gchar* reason = args[2]; if (window->type != WIN_MUC) { cons_show("You must be in a chat room to send an invite."); @@ -4017,7 +3997,7 @@ cmd_form(ProfWin* window, const char* const command, gchar** args) } if (g_strcmp0(args[0], "help") == 0) { - char* tag = args[1]; + gchar* tag = args[1]; if (tag) { confwin_field_help(confwin, tag); } else { @@ -4081,10 +4061,10 @@ cmd_kick(ProfWin* window, const char* const command, gchar** args) ProfMucWin* mucwin = (ProfMucWin*)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - char* nick = args[0]; + gchar* nick = args[0]; if (nick) { if (muc_roster_contains_nick(mucwin->roomjid, nick)) { - char* reason = args[1]; + gchar* reason = args[1]; iq_room_kick_occupant(mucwin->roomjid, nick, reason); } else { win_println(window, THEME_DEFAULT, "!", "Occupant does not exist: %s", nick); @@ -4114,9 +4094,9 @@ cmd_ban(ProfWin* window, const char* const command, gchar** args) ProfMucWin* mucwin = (ProfMucWin*)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - char* jid = args[0]; + gchar* jid = args[0]; if (jid) { - char* reason = args[1]; + gchar* reason = args[1]; iq_room_affiliation_set(mucwin->roomjid, jid, "outcast", reason); } else { cons_bad_cmd_usage(command); @@ -4245,13 +4225,13 @@ cmd_affiliation(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* cmd = args[0]; + gchar* cmd = args[0]; if (cmd == NULL) { cons_bad_cmd_usage(command); return TRUE; } - char* affiliation = args[1]; + gchar* affiliation = args[1]; if (!_string_matches_one_of(NULL, affiliation, TRUE, "owner", "admin", "member", "none", "outcast", NULL)) { cons_bad_cmd_usage(command); return TRUE; @@ -4280,12 +4260,12 @@ cmd_affiliation(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* jid = args[2]; + gchar* jid = args[2]; if (jid == NULL) { cons_bad_cmd_usage(command); return TRUE; } else { - char* reason = args[3]; + gchar* reason = args[3]; iq_room_affiliation_set(mucwin->roomjid, jid, affiliation, reason); return TRUE; } @@ -4320,13 +4300,13 @@ cmd_role(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* cmd = args[0]; + gchar* cmd = args[0]; if (cmd == NULL) { cons_bad_cmd_usage(command); return TRUE; } - char* role = args[1]; + gchar* role = args[1]; if (!_string_matches_one_of(NULL, role, TRUE, "visitor", "participant", "moderator", "none", NULL)) { cons_bad_cmd_usage(command); return TRUE; @@ -4426,7 +4406,7 @@ cmd_occupants(ProfWin* window, const char* const command, gchar** args) return TRUE; } else { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg); if (res) { prefs_set_occupants_size(intval); @@ -4435,7 +4415,6 @@ cmd_occupants(ProfWin* window, const char* const command, gchar** args) return TRUE; } else { cons_show(err_msg); - free(err_msg); return TRUE; } } @@ -4447,7 +4426,7 @@ cmd_occupants(ProfWin* window, const char* const command, gchar** args) return TRUE; } else { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[1], &intval, 0, 10, &err_msg); if (res) { prefs_set_occupants_indent(intval); @@ -4456,7 +4435,6 @@ cmd_occupants(ProfWin* window, const char* const command, gchar** args) occupantswin_occupants_all(); } else { cons_show(err_msg); - free(err_msg); } return TRUE; } @@ -4947,7 +4925,7 @@ _add_omemo_stream(int* fd, FILE** fh, char** err) { // Create temporary file for writing ciphertext. int tmpfd; - char* tmpname = NULL; + auto_char char* tmpname = NULL; if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) { *err = "Unable to create temporary file for encrypted transfer."; return NULL; @@ -4957,7 +4935,6 @@ _add_omemo_stream(int* fd, FILE** fh, char** err) // The temporary ciphertext file should be removed after it has // been closed. remove(tmpname); - free(tmpname); int crypt_res; char* fragment; @@ -4985,7 +4962,7 @@ gboolean cmd_sendfile(ProfWin* window, const char* const command, gchar** args) { jabber_conn_status_t conn_status = connection_get_status(); - gchar* filename; + auto_gchar gchar* filename; char* alt_scheme = NULL; char* alt_fragment = NULL; @@ -5093,8 +5070,6 @@ out: if (alt_fragment != NULL) omemo_free(alt_fragment); #endif - if (filename != NULL) - free(filename); return TRUE; } @@ -6087,7 +6062,7 @@ cmd_inpblock(ProfWin* window, const char* const command, gchar** args) } int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, 1, 1000, &err_msg); if (res) { cons_show("Input blocking set to %d milliseconds.", intval); @@ -6095,7 +6070,6 @@ cmd_inpblock(ProfWin* window, const char* const command, gchar** args) inp_nonblocking(FALSE); } else { cons_show(err_msg); - free(err_msg); } return TRUE; @@ -6308,7 +6282,7 @@ cmd_statusbar(ProfWin* window, const char* const command, gchar** args) char* value = args[1]; int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { if (intval < 0 || intval > 10) { @@ -6327,7 +6301,6 @@ cmd_statusbar(ProfWin* window, const char* const command, gchar** args) } else { cons_show(err_msg); cons_bad_cmd_usage(command); - free(err_msg); return TRUE; } } @@ -6340,7 +6313,7 @@ cmd_statusbar(ProfWin* window, const char* const command, gchar** args) char* value = args[1]; int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { if (intval < 0) { @@ -6359,7 +6332,6 @@ cmd_statusbar(ProfWin* window, const char* const command, gchar** args) } else { cons_show(err_msg); cons_bad_cmd_usage(command); - free(err_msg); return TRUE; } } @@ -6519,14 +6491,13 @@ cmd_log(ProfWin* window, const char* const command, gchar** args) if (strcmp(subcmd, "maxsize") == 0) { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); if (res) { prefs_set_max_log_size(intval); cons_show("Log maximum size set to %d bytes", intval); } else { cons_show(err_msg); - free(err_msg); } return TRUE; } @@ -6564,7 +6535,7 @@ cmd_reconnect(ProfWin* window, const char* const command, gchar** args) char* value = args[0]; int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; if (g_strcmp0(value, "now") == 0) { cons_show("Reconnecting now."); cl_ev_reconnect(); @@ -6578,7 +6549,6 @@ cmd_reconnect(ProfWin* window, const char* const command, gchar** args) } else { cons_show(err_msg); cons_bad_cmd_usage(command); - free(err_msg); } return TRUE; @@ -6592,7 +6562,7 @@ cmd_autoping(ProfWin* window, const char* const command, gchar** args) if (g_strcmp0(cmd, "set") == 0) { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { prefs_set_autoping(intval); @@ -6605,12 +6575,11 @@ cmd_autoping(ProfWin* window, const char* const command, gchar** args) } else { cons_show(err_msg); cons_bad_cmd_usage(command); - free(err_msg); } } else if (g_strcmp0(cmd, "timeout") == 0) { int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { prefs_set_autoping_timeout(intval); @@ -6622,7 +6591,6 @@ cmd_autoping(ProfWin* window, const char* const command, gchar** args) } else { cons_show(err_msg); cons_bad_cmd_usage(command); - free(err_msg); } } else { @@ -6681,7 +6649,7 @@ cmd_autoaway(ProfWin* window, const char* const command, gchar** args) if ((g_strcmp0(args[0], "time") == 0) && (args[2] != NULL)) { if (g_strcmp0(args[1], "away") == 0) { int minutesval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[2], &minutesval, 1, INT_MAX, &err_msg); if (res) { prefs_set_autoaway_time(minutesval); @@ -6692,13 +6660,12 @@ cmd_autoaway(ProfWin* window, const char* const command, gchar** args) } } else { cons_show(err_msg); - free(err_msg); } return TRUE; } else if (g_strcmp0(args[1], "xa") == 0) { int minutesval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[2], &minutesval, 0, INT_MAX, &err_msg); if (res) { int away_time = prefs_get_autoaway_time(); @@ -6716,7 +6683,6 @@ cmd_autoaway(ProfWin* window, const char* const command, gchar** args) } } else { cons_show(err_msg); - free(err_msg); } return TRUE; @@ -6775,7 +6741,7 @@ cmd_priority(ProfWin* window, const char* const command, gchar** args) char* value = args[0]; int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg); if (res) { accounts_set_priority_all(session_get_account_name(), intval); @@ -6784,7 +6750,6 @@ cmd_priority(ProfWin* window, const char* const command, gchar** args) cons_show("Priority set to %d.", intval); } else { cons_show(err_msg); - free(err_msg); } return TRUE; @@ -6841,7 +6806,7 @@ cmd_tray(ProfWin* window, const char* const command, gchar** args) } int intval = 0; - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(args[1], &intval, 1, 10, &err_msg); if (res) { if (intval == 1) { @@ -6855,7 +6820,6 @@ cmd_tray(ProfWin* window, const char* const command, gchar** args) } } else { cons_show(err_msg); - free(err_msg); } return TRUE; @@ -7115,6 +7079,7 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args) cons_show("Plugins must have one of the following extensions: \".py\" or \".so\"."); return TRUE; } + GString* error_message = g_string_new(NULL); auto_gchar gchar* plugin_name = g_path_get_basename(path); gboolean result = plugins_install(plugin_name, path, error_message); @@ -7462,9 +7427,8 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args) ProfPGPKey* key = g_hash_table_lookup(keys, curr->data); cons_show(" %s", key->name); cons_show(" ID : %s", key->id); - char* format_fp = p_gpg_format_fp_str(key->fp); + auto_char char* format_fp = p_gpg_format_fp_str(key->fp); cons_show(" Fingerprint : %s", format_fp); - free(format_fp); if (key->secret) { cons_show(" Type : PUBLIC, PRIVATE"); } else { @@ -7753,9 +7717,8 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args) ProfPGPKey* key = g_hash_table_lookup(keys, curr->data); cons_show(" %s", key->name); cons_show(" ID : %s", key->id); - char* format_fp = p_gpg_format_fp_str(key->fp); + auto_char char* format_fp = p_gpg_format_fp_str(key->fp); cons_show(" Fingerprint : %s", format_fp); - free(format_fp); if (key->secret) { cons_show(" Type : PUBLIC, PRIVATE"); } else { @@ -7890,22 +7853,19 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args) return TRUE; } else if (g_strcmp0(args[0], "announce") == 0) { if (args[1]) { - gchar* filename = get_expanded_path(args[1]); + auto_gchar gchar* filename = get_expanded_path(args[1]); if (access(filename, R_OK) != 0) { cons_show_error("File not found: %s", filename); - g_free(filename); return TRUE; } if (!is_regular_file(filename)) { cons_show_error("Not a file: %s", filename); - g_free(filename); return TRUE; } ox_announce_public_key(filename); - free(filename); } else { cons_show("Filename is required"); } @@ -8091,9 +8051,8 @@ cmd_otr_myfp(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* fingerprint = otr_get_my_fingerprint(); + auto_char char* fingerprint = otr_get_my_fingerprint(); win_println(window, THEME_DEFAULT, "!", "Your OTR fingerprint: %s", fingerprint); - free(fingerprint); return TRUE; #else cons_show("This version of Profanity has not been built with OTR support enabled"); @@ -8122,9 +8081,8 @@ cmd_otr_theirfp(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* fingerprint = otr_get_their_fingerprint(chatwin->barejid); + auto_char char* fingerprint = otr_get_their_fingerprint(chatwin->barejid); win_println(window, THEME_DEFAULT, "!", "%s's OTR fingerprint: %s", chatwin->barejid, fingerprint); - free(fingerprint); return TRUE; #else cons_show("This version of Profanity has not been built with OTR support enabled"); @@ -8177,8 +8135,7 @@ cmd_otr_start(ProfWin* window, const char* const command, gchar** args) if (!otr_is_secure(barejid)) { char* otr_query_message = otr_start_query(); - char* id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); - free(id); + free(message_send_chat_otr(barejid, otr_query_message, FALSE, NULL)); return TRUE; } @@ -8210,9 +8167,8 @@ cmd_otr_start(ProfWin* window, const char* const command, gchar** args) } char* otr_query_message = otr_start_query(); - char* id = message_send_chat_otr(chatwin->barejid, otr_query_message, FALSE, NULL); + free(message_send_chat_otr(chatwin->barejid, otr_query_message, FALSE, NULL)); - free(id); return TRUE; } #else @@ -8684,13 +8640,11 @@ _cmd_execute_alias(ProfWin* window, const char* const inp, gboolean* ran) return TRUE; } - char* alias = strdup(inp + 1); - char* value = prefs_get_alias(alias); - free(alias); + auto_char char* alias = strdup(inp + 1); + auto_gchar gchar* value = prefs_get_alias(alias); if (value) { *ran = TRUE; gboolean result = cmd_process_input(window, value); - g_free(value); return result; } @@ -9000,12 +8954,11 @@ cmd_omemo_fingerprint(ProfWin* window, const char* const command, gchar** args) return TRUE; } - Jid* jid; + auto_jid Jid* jid; if (!args[1]) { if (window->type == WIN_CONSOLE) { - char* fingerprint = omemo_own_fingerprint(TRUE); + auto_char char* fingerprint = omemo_own_fingerprint(TRUE); cons_show("Your OMEMO fingerprint: %s", fingerprint); - free(fingerprint); jid = jid_create(connection_get_fulljid()); } else if (window->type == WIN_CHAT) { ProfChatWin* chatwin = (ProfChatWin*)window; @@ -9035,15 +8988,12 @@ cmd_omemo_fingerprint(ProfWin* window, const char* const command, gchar** args) } for (GList* fingerprint = fingerprints; fingerprint != NULL; fingerprint = fingerprint->next) { - char* formatted_fingerprint = omemo_format_fingerprint(fingerprint->data); + auto_char char* formatted_fingerprint = omemo_format_fingerprint(fingerprint->data); gboolean trusted = omemo_is_trusted_identity(jid->barejid, fingerprint->data); win_println(window, THEME_DEFAULT, "-", "%s's OMEMO fingerprint: %s%s", jid->barejid, formatted_fingerprint, trusted ? " (trusted)" : ""); - - free(formatted_fingerprint); } - jid_destroy(jid); g_list_free(fingerprints); win_println(window, THEME_DEFAULT, "-", "You can trust it with '/omemo trust [] '"); @@ -9101,7 +9051,7 @@ cmd_omemo_trust(ProfWin* window, const char* const command, gchar** args) omemo_trust(barejid, fingerprint); - char* unformatted_fingerprint = malloc(strlen(fingerprint)); + auto_char char* unformatted_fingerprint = malloc(strlen(fingerprint)); int i; int j; for (i = 0, j = 0; fingerprint[i] != '\0'; i++) { @@ -9116,8 +9066,6 @@ cmd_omemo_trust(ProfWin* window, const char* const command, gchar** args) win_println(window, THEME_DEFAULT, "-", "%s's OMEMO fingerprint: %s%s", barejid, fingerprint, trusted ? " (trusted)" : ""); - free(unformatted_fingerprint); - return TRUE; #else cons_show("This version of Profanity has not been built with OMEMO support enabled"); @@ -9170,7 +9118,7 @@ cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** args) omemo_untrust(barejid, fingerprint); - char* unformatted_fingerprint = malloc(strlen(fingerprint)); + auto_char char* unformatted_fingerprint = malloc(strlen(fingerprint)); int i, j; for (i = 0, j = 0; fingerprint[i] != '\0'; i++) { if (!g_ascii_isxdigit(fingerprint[i])) { @@ -9184,8 +9132,6 @@ cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** args) win_println(window, THEME_DEFAULT, "-", "%s's OMEMO fingerprint: %s%s", barejid, fingerprint, trusted ? " (trusted)" : ""); - free(unformatted_fingerprint); - return TRUE; #else cons_show("This version of Profanity has not been built with OMEMO support enabled"); @@ -9249,9 +9195,8 @@ cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* qrstr = omemo_qrcode_str(); + auto_char char* qrstr = omemo_qrcode_str(); cons_show_qrcode(qrstr); - free(qrstr); return TRUE; #else @@ -9282,7 +9227,7 @@ gboolean cmd_paste(ProfWin* window, const char* const command, gchar** args) { #ifdef HAVE_GTK - char* clipboard_buffer = clipboard_get(); + auto_char char* clipboard_buffer = clipboard_get(); if (clipboard_buffer) { switch (window->type) { @@ -9313,8 +9258,6 @@ cmd_paste(ProfWin* window, const char* const command, gchar** args) cons_bad_cmd_usage(command); break; } - - free(clipboard_buffer); } #else cons_show("This version of Profanity has not been built with GTK support enabled. It is needed for the clipboard feature to work."); @@ -9524,18 +9467,14 @@ cmd_correct(ProfWin* window, const char* const command, gchar** args) ProfChatWin* chatwin = (ProfChatWin*)window; // send message again, with replace flag - gchar* message = g_strjoinv(" ", args); + auto_gchar gchar* message = g_strjoinv(" ", args); cl_ev_send_msg_correct(chatwin, message, FALSE, TRUE); - - free(message); } else if (window->type == WIN_MUC) { ProfMucWin* mucwin = (ProfMucWin*)window; // send message again, with replace flag - gchar* message = g_strjoinv(" ", args); + auto_gchar gchar* message = g_strjoinv(" ", args); cl_ev_send_muc_msg_corrected(mucwin, message, FALSE, TRUE); - - free(message); } return TRUE; @@ -9612,12 +9551,12 @@ _download_install_plugin(ProfWin* window, gchar* url, gchar* path) return TRUE; } -static gchar* +void _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* path) { auto_gchar gchar* filename = _prepare_filename(url, path); if (!filename) - return NULL; + return; auto_char char* id = get_random_string(4); HTTPDownload* download = malloc(sizeof(HTTPDownload)); download->window = window; @@ -9628,7 +9567,6 @@ _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* p pthread_create(&(download->worker), NULL, &http_file_get, download); http_download_add_download(download); - return g_strdup(filename); } void @@ -9715,7 +9653,7 @@ cmd_url_save(ProfWin* window, const char* const command, gchar** args) auto_gchar gchar* cmd_template = prefs_get_string(PREF_URL_SAVE_CMD); if (cmd_template == NULL && (g_strcmp0(scheme, "http") == 0 || g_strcmp0(scheme, "https") == 0)) { - g_free(_url_http_method(window, cmd_template, url, path)); + _url_http_method(window, cmd_template, url, path); #ifdef HAVE_OMEMO } else if (g_strcmp0(scheme, "aesgcm") == 0) { _url_aesgcm_method(window, cmd_template, url, path); @@ -9810,9 +9748,9 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args) return TRUE; } - char* user = connection_get_user(); - char* passwd = ui_ask_password(false); - char* confirm_passwd = ui_ask_password(true); + auto_char char* user = connection_get_user(); + auto_char char* passwd = ui_ask_password(false); + auto_char char* confirm_passwd = ui_ask_password(true); if (g_strcmp0(passwd, confirm_passwd) == 0) { iq_register_change_password(user, passwd); @@ -9820,17 +9758,13 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args) cons_show("Aborted! The new password and the confirmed password do not match."); } - free(user); - free(passwd); - free(confirm_passwd); - return TRUE; } gboolean cmd_editor(ProfWin* window, const char* const command, gchar** args) { - gchar* message = NULL; + auto_gchar gchar* message = NULL; if (get_message_from_editor(NULL, &message)) { return TRUE; @@ -9840,7 +9774,6 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args) ui_resize(); rl_point = rl_end; rl_forced_update_display(); - g_free(message); return TRUE; } @@ -9854,7 +9787,7 @@ cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) gchar* initial_message = win_get_last_sent_message(window); - gchar* message = NULL; + auto_gchar gchar* message = NULL; if (get_message_from_editor(initial_message, &message)) { return TRUE; } @@ -9869,8 +9802,6 @@ cmd_correct_editor(ProfWin* window, const char* const command, gchar** args) cl_ev_send_muc_msg_corrected(mucwin, message, FALSE, TRUE); } - g_free(message); - return TRUE; } @@ -9907,12 +9838,11 @@ cmd_register(ProfWin* window, const char* const command, gchar** args) int port = 0; if (g_hash_table_contains(options, "port")) { char* port_str = g_hash_table_lookup(options, "port"); - char* err_msg = NULL; + auto_char char* err_msg = NULL; gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); - free(err_msg); port = 0; options_destroy(options); return TRUE; @@ -9922,8 +9852,8 @@ cmd_register(ProfWin* window, const char* const command, gchar** args) char* username = args[0]; char* server = args[1]; - char* passwd = ui_ask_password(false); - char* confirm_passwd = ui_ask_password(true); + auto_char char* passwd = ui_ask_password(false); + auto_char char* confirm_passwd = ui_ask_password(true); if (g_strcmp0(passwd, confirm_passwd) == 0) { log_info("Attempting to register account %s on server %s.", username, server); @@ -9938,9 +9868,6 @@ cmd_register(ProfWin* window, const char* const command, gchar** args) return TRUE; } - free(passwd); - free(confirm_passwd); - options_destroy(options); log_info("we are leaving the registration process"); diff --git a/src/common.c b/src/common.c index c1a47c2d..cdfc9e53 100644 --- a/src/common.c +++ b/src/common.c @@ -143,11 +143,10 @@ str_replace(const char* string, const char* substr, head = newstr; while ((tok = strstr(head, substr))) { - char* oldstr = newstr; + auto_char char* oldstr = newstr; newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1); if (newstr == NULL) { - free(oldstr); return NULL; } @@ -159,7 +158,6 @@ str_replace(const char* string, const char* substr, memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1); head = newstr + (tok - oldstr) + strlen(replacement); - free(oldstr); } return newstr; @@ -282,10 +280,10 @@ _data_callback(void* ptr, size_t size, size_t nmemb, void* data) return realsize; } -char* -get_file_or_linked(char* loc, char* basedir) +gchar* +get_file_or_linked(gchar* loc, gchar* basedir) { - char* true_loc = NULL; + gchar* true_loc = NULL; // check for symlink if (g_file_test(loc, G_FILE_TEST_IS_SYMLINK)) { @@ -293,13 +291,13 @@ get_file_or_linked(char* loc, char* basedir) // if relative, add basedir if (!g_str_has_prefix(true_loc, "/") && !g_str_has_prefix(true_loc, "~")) { - char* tmp = g_strdup_printf("%s/%s", basedir, true_loc); - free(true_loc); + gchar* tmp = g_strdup_printf("%s/%s", basedir, true_loc); + g_free(true_loc); true_loc = tmp; } // use given location } else { - true_loc = strdup(loc); + true_loc = g_strdup(loc); } return true_loc; diff --git a/src/common.h b/src/common.h index da6bd2b6..133338b3 100644 --- a/src/common.h +++ b/src/common.h @@ -110,7 +110,7 @@ int utf8_display_len(const char* const str); char* release_get_latest(void); gboolean release_is_new(char* found_version); -char* get_file_or_linked(char* loc, char* basedir); +gchar* get_file_or_linked(gchar* loc, gchar* basedir); char* strip_arg_quotes(const char* const input); gboolean is_notify_enabled(void); diff --git a/src/config/accounts.c b/src/config/accounts.c index d5747cbf..b5b1ecce 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -53,7 +53,7 @@ #include "xmpp/xmpp.h" #include "xmpp/jid.h" -static char* accounts_loc; +static gchar* accounts_loc; static GKeyFile* accounts; static Autocomplete all_ac; @@ -861,9 +861,8 @@ accounts_set_last_activity(const char* const account_name) g_date_time_unref(nowdt); if (res) { - char* timestr = g_time_val_to_iso8601(&nowtv); + auto_char char* timestr = g_time_val_to_iso8601(&nowtv); g_key_file_set_string(accounts, account_name, "last.activity", timestr); - free(timestr); _save_accounts(); } } @@ -942,7 +941,7 @@ resource_presence_t accounts_get_login_presence(const char* const account_name) { resource_presence_t result; - gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); + auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); if (setting == NULL || (strcmp(setting, "online") == 0)) { result = RESOURCE_ONLINE; @@ -961,21 +960,19 @@ accounts_get_login_presence(const char* const account_name) result = RESOURCE_ONLINE; } - g_free(setting); return result; } char* accounts_get_login_status(const char* const account_name) { - gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); + auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); gchar* status = NULL; if (g_strcmp0(setting, "last") == 0) { status = accounts_get_last_status(account_name); } - g_free(setting); return status; } @@ -983,14 +980,10 @@ static void _save_accounts(void) { gsize g_data_size; - gchar* g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); + auto_gchar gchar* g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); - gchar* base = g_path_get_dirname(accounts_loc); - gchar* true_loc = get_file_or_linked(accounts_loc, base); + auto_gchar gchar* base = g_path_get_dirname(accounts_loc); + auto_gchar gchar* true_loc = get_file_or_linked(accounts_loc, base); g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL); g_chmod(accounts_loc, S_IRUSR | S_IWUSR); - - g_free(base); - free(true_loc); - g_free(g_accounts_data); } diff --git a/src/config/cafile.c b/src/config/cafile.c index 542740d0..97150a85 100644 --- a/src/config/cafile.c +++ b/src/config/cafile.c @@ -49,13 +49,11 @@ static gchar* _cafile_name(void) { - gchar* certs_dir = files_get_data_path(DIR_CERTS); + auto_gchar gchar* certs_dir = files_get_data_path(DIR_CERTS); if (!create_dir(certs_dir)) { - g_free(certs_dir); return NULL; } gchar* filename = g_strdup_printf("%s/CAfile.pem", certs_dir); - g_free(certs_dir); return filename; } diff --git a/src/config/color.c b/src/config/color.c index 9c1998f5..ecadc36b 100644 --- a/src/config/color.c +++ b/src/config/color.c @@ -35,6 +35,7 @@ */ #include "config.h" +#include "common.h" #include #include @@ -508,10 +509,9 @@ color_pair_cache_hash_str(const char* str, color_profile profile) int fg = color_hash(str, profile); int bg = -1; - char* bkgnd = theme_get_bkgnd(); + auto_char char* bkgnd = theme_get_bkgnd(); if (bkgnd) { bg = find_col(bkgnd, strlen(bkgnd)); - free(bkgnd); } return _color_pair_cache_get(fg, bg); diff --git a/src/config/files.c b/src/config/files.c index 75940c90..a7a10162 100644 --- a/src/config/files.c +++ b/src/config/files.c @@ -117,7 +117,7 @@ files_get_inputrc_file(void) gchar* files_get_log_file(const char* const log_file) { - gchar* xdg_data = _files_get_xdg_data_home(); + auto_gchar gchar* xdg_data = _files_get_xdg_data_home(); GString* logfile; if (log_file) { @@ -141,7 +141,6 @@ files_get_log_file(const char* const log_file) gchar* result = g_strdup(logfile->str); - free(xdg_data); g_string_free(logfile, TRUE); return result; @@ -156,27 +155,30 @@ files_get_config_path(const char* const config_base) return result; } +/** + * Get the full path by appending the given location to the project base path. + * + * @param location The location (directory or file) to append to the project base path. + * @return The full path obtained by appending the location to the project base path. + * + * @note The returned value must be freed using g_free when it is no longer needed + * to prevent memory leaks. + */ gchar* -files_get_data_path(const char* const data_base) +files_get_data_path(const char* const location) { - gchar* xdg_data = _files_get_xdg_data_home(); - gchar* result = g_strdup_printf("%s/profanity/%s", xdg_data, data_base); - g_free(xdg_data); + auto_gchar gchar* xdg_data = _files_get_xdg_data_home(); + gchar* result = g_strdup_printf("%s/profanity/%s", xdg_data, location); return result; } gchar* files_get_account_data_path(const char* const specific_dir, const char* const jid) { - gchar* data_dir = files_get_data_path(specific_dir); - gchar* account_dir = str_replace(jid, "@", "_at_"); + auto_gchar gchar* data_dir = files_get_data_path(specific_dir); + auto_gchar gchar* account_dir = str_replace(jid, "@", "_at_"); - gchar* result = g_strdup_printf("%s/%s", data_dir, account_dir); - - g_free(account_dir); - g_free(data_dir); - - return result; + return g_strdup_printf("%s/%s", data_dir, account_dir); } gchar* diff --git a/src/config/files.h b/src/config/files.h index 50116d88..2664a903 100644 --- a/src/config/files.h +++ b/src/config/files.h @@ -65,7 +65,7 @@ void files_create_directories(void); gchar* files_get_config_path(const char* const config_base); -gchar* files_get_data_path(const char* const data_base); +gchar* files_get_data_path(const char* const location); gchar* files_get_account_data_path(const char* const specific_dir, const char* const jid); gchar* files_get_log_file(const char* const log_file); diff --git a/src/config/preferences.c b/src/config/preferences.c index c1b57599..2b21b81e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -288,7 +288,7 @@ prefs_close(void) prefs_loc = NULL; } -char* +gchar* prefs_autocomplete_boolean_choice(const char* const prefix, gboolean previous, void* context) { return autocomplete_complete(boolean_choice_ac, prefix, TRUE, previous); @@ -300,7 +300,7 @@ prefs_reset_boolean_choice(void) autocomplete_reset(boolean_choice_ac); } -char* +gchar* prefs_autocomplete_room_trigger(const char* const prefix, gboolean previous, void* context) { return autocomplete_complete(room_trigger_ac, prefix, TRUE, previous); @@ -1631,7 +1631,7 @@ prefs_add_alias(const char* const name, const char* const value) } } -char* +gchar* prefs_get_alias(const char* const name) { return g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL); @@ -1704,16 +1704,12 @@ static void _save_prefs(void) { gsize g_data_size; - gchar* g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL); - gchar* base = g_path_get_dirname(prefs_loc); - gchar* true_loc = get_file_or_linked(prefs_loc, base); + auto_gchar gchar* g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL); + auto_gchar gchar* base = g_path_get_dirname(prefs_loc); + auto_gchar gchar* true_loc = get_file_or_linked(prefs_loc, base); g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL); g_chmod(prefs_loc, S_IRUSR | S_IWUSR); - - g_free(base); - free(true_loc); - g_free(g_prefs_data); } // get the preference group for a specific preference diff --git a/src/config/preferences.h b/src/config/preferences.h index bc53abfb..9df1f341 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -213,10 +213,10 @@ void prefs_reload(void); char* prefs_find_login(char* prefix); void prefs_reset_login_search(void); -char* prefs_autocomplete_boolean_choice(const char* const prefix, gboolean previous, void* context); +gchar* prefs_autocomplete_boolean_choice(const char* const prefix, gboolean previous, void* context); void prefs_reset_boolean_choice(void); -char* prefs_autocomplete_room_trigger(const char* const prefix, gboolean previous, void* context); +gchar* prefs_autocomplete_room_trigger(const char* const prefix, gboolean previous, void* context); void prefs_reset_room_trigger_ac(void); gint prefs_get_gone(void); @@ -311,7 +311,7 @@ gint prefs_get_tray_timer(void); gboolean prefs_add_alias(const char* const name, const char* const value); gboolean prefs_remove_alias(const char* const name); -char* prefs_get_alias(const char* const name); +gchar* prefs_get_alias(const char* const name); GList* prefs_get_aliases(void); void prefs_free_aliases(GList* aliases); diff --git a/src/config/scripts.c b/src/config/scripts.c index aca85173..7211af7e 100644 --- a/src/config/scripts.c +++ b/src/config/scripts.c @@ -54,7 +54,7 @@ void scripts_init(void) { - char* scriptsdir = files_get_data_path(DIR_SCRIPTS); + auto_gchar gchar* scriptsdir = files_get_data_path(DIR_SCRIPTS); // mkdir if doesn't exist errno = 0; @@ -67,18 +67,15 @@ scripts_init(void) log_error("Error creating directory: %s", scriptsdir); } } - - free(scriptsdir); } GSList* scripts_list(void) { - char* scriptsdir = files_get_data_path(DIR_SCRIPTS); + auto_gchar gchar* scriptsdir = files_get_data_path(DIR_SCRIPTS); GSList* result = NULL; GDir* scripts = g_dir_open(scriptsdir, 0, NULL); - free(scriptsdir); if (scripts) { const gchar* script = g_dir_read_name(scripts); @@ -95,9 +92,8 @@ scripts_list(void) GSList* scripts_read(const char* const script) { - char* scriptsdir = files_get_data_path(DIR_SCRIPTS); + auto_gchar gchar* scriptsdir = files_get_data_path(DIR_SCRIPTS); GString* scriptpath = g_string_new(scriptsdir); - free(scriptsdir); g_string_append(scriptpath, "/"); g_string_append(scriptpath, script); @@ -110,7 +106,7 @@ scripts_read(const char* const script) g_string_free(scriptpath, TRUE); - char* line = NULL; + auto_char char* line = NULL; size_t len = 0; GSList* result = NULL; @@ -123,8 +119,6 @@ scripts_read(const char* const script) } fclose(scriptfile); - if (line) - free(line); return result; } @@ -132,9 +126,8 @@ scripts_read(const char* const script) gboolean scripts_exec(const char* const script) { - char* scriptsdir = files_get_data_path(DIR_SCRIPTS); + auto_gchar gchar* scriptsdir = files_get_data_path(DIR_SCRIPTS); GString* scriptpath = g_string_new(scriptsdir); - free(scriptsdir); g_string_append(scriptpath, "/"); g_string_append(scriptpath, script); @@ -147,7 +140,7 @@ scripts_exec(const char* const script) g_string_free(scriptpath, TRUE); - char* line = NULL; + auto_char char* line = NULL; size_t len = 0; while (getline(&line, &len, scriptfile) != -1) { @@ -158,8 +151,6 @@ scripts_exec(const char* const script) } fclose(scriptfile); - if (line) - free(line); return TRUE; } diff --git a/src/database.c b/src/database.c index 87fd9094..58a2cd07 100644 --- a/src/database.c +++ b/src/database.c @@ -83,7 +83,7 @@ log_database_init(ProfAccount* account) return FALSE; } - char* filename = _get_db_filename(account); + auto_char char* filename = _get_db_filename(account); if (!filename) { return FALSE; } @@ -92,7 +92,6 @@ log_database_init(ProfAccount* account) if (ret != SQLITE_OK) { const char* err_msg = sqlite3_errmsg(g_chatlog_database); log_error("Error opening SQLite database: %s", err_msg); - free(filename); return FALSE; } @@ -126,7 +125,6 @@ log_database_init(ProfAccount* account) } log_debug("Initialized SQLite database: %s", filename); - free(filename); return TRUE; out: @@ -136,7 +134,6 @@ out: } else { log_error("Unknown SQLite error"); } - free(filename); return FALSE; } diff --git a/src/event/client_events.c b/src/event/client_events.c index c393ccd4..e8620234 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -110,7 +110,7 @@ cl_ev_reconnect(void) void cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs) { - char* signed_status = NULL; + auto_char char* signed_status = NULL; #ifdef HAVE_LIBGPGME char* account_name = session_get_account_name(); @@ -123,8 +123,6 @@ cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs #endif presence_send(presence_type, idle_secs, signed_status); - - free(signed_status); } void @@ -134,7 +132,7 @@ cl_ev_send_msg_correct(ProfChatWin* chatwin, const char* const msg, const char* gboolean request_receipt = prefs_get_boolean(PREF_RECEIPTS_REQUEST); - char* plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg); + auto_char char* plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg); if (plugin_msg == NULL) { return; } @@ -146,33 +144,30 @@ cl_ev_send_msg_correct(ProfChatWin* chatwin, const char* const msg, const char* if (chatwin->is_omemo) { #ifdef HAVE_OMEMO - char* id = omemo_on_message_send((ProfWin*)chatwin, plugin_msg, request_receipt, FALSE, replace_id); + auto_char char* id = omemo_on_message_send((ProfWin*)chatwin, plugin_msg, request_receipt, FALSE, replace_id); if (id != NULL) { chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL); log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id); - free(id); } #endif } else if (chatwin->is_ox) { #ifdef HAVE_LIBGPGME // XEP-0373: OpenPGP for XMPP - char* id = message_send_chat_ox(chatwin->barejid, plugin_msg, request_receipt, replace_id); + auto_char char* id = message_send_chat_ox(chatwin->barejid, plugin_msg, request_receipt, replace_id); if (id != NULL) { chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OX); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OX, request_receipt, replace_id); - free(id); } #endif } else if (chatwin->pgp_send) { #ifdef HAVE_LIBGPGME - char* id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id); + auto_char char* id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id); if (id != NULL) { chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL); log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id); - free(id); } #endif } else { @@ -181,16 +176,14 @@ cl_ev_send_msg_correct(ProfChatWin* chatwin, const char* const msg, const char* handled = otr_on_message_send(chatwin, plugin_msg, request_receipt, replace_id); #endif if (!handled) { - char* id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); + auto_char char* id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, plugin_msg, NULL); log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE); chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id); - free(id); } } plugins_post_chat_message_send(chatwin->barejid, plugin_msg); - free(plugin_msg); return; } @@ -203,7 +196,7 @@ cl_ev_send_msg(ProfChatWin* chatwin, const char* const msg, const char* const oo void cl_ev_send_muc_msg_corrected(ProfMucWin* mucwin, const char* const msg, const char* const oob_url, gboolean correct_last_msg) { - char* plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg); + auto_char char* plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg); if (plugin_msg == NULL) { return; } @@ -215,33 +208,28 @@ cl_ev_send_muc_msg_corrected(ProfMucWin* mucwin, const char* const msg, const ch #ifdef HAVE_OMEMO if (mucwin->is_omemo) { - char* id = omemo_on_message_send((ProfWin*)mucwin, plugin_msg, FALSE, TRUE, replace_id); + auto_char char* id = omemo_on_message_send((ProfWin*)mucwin, plugin_msg, FALSE, TRUE, replace_id); groupchat_log_omemo_msg_out(mucwin->roomjid, plugin_msg); log_database_add_outgoing_muc(id, mucwin->roomjid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO); mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, replace_id); - free(id); } else { - char* id = message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url, replace_id); + auto_char char* id = message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url, replace_id); groupchat_log_msg_out(mucwin->roomjid, plugin_msg); log_database_add_outgoing_muc(id, mucwin->roomjid, plugin_msg, replace_id, PROF_MSG_ENC_NONE); mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_ENC_NONE, replace_id); - free(id); } plugins_post_room_message_send(mucwin->roomjid, plugin_msg); - free(plugin_msg); return; #endif #ifndef HAVE_OMEMO - char* id = message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url, replace_id); + auto_char char* id = message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url, replace_id); groupchat_log_msg_out(mucwin->roomjid, plugin_msg); log_database_add_outgoing_muc(id, mucwin->roomjid, plugin_msg, replace_id, PROF_MSG_ENC_NONE); mucwin_outgoing_msg(mucwin, plugin_msg, id, PROF_MSG_ENC_NONE, replace_id); - free(id); plugins_post_room_message_send(mucwin->roomjid, plugin_msg); - free(plugin_msg); return; #endif } @@ -260,18 +248,14 @@ cl_ev_send_priv_msg(ProfPrivateWin* privwin, const char* const msg, const char* } else if (privwin->room_left) { privwin_message_left_room(privwin); } else { - char* plugin_msg = plugins_pre_priv_message_send(privwin->fulljid, msg); - Jid* jidp = jid_create(privwin->fulljid); + auto_char char* plugin_msg = plugins_pre_priv_message_send(privwin->fulljid, msg); + auto_jid Jid* jidp = jid_create(privwin->fulljid); - char* id = message_send_private(privwin->fulljid, plugin_msg, oob_url); + auto_char char* id = message_send_private(privwin->fulljid, plugin_msg, oob_url); chat_log_msg_out(jidp->barejid, plugin_msg, jidp->resourcepart); log_database_add_outgoing_muc_pm(id, privwin->fulljid, plugin_msg, NULL, PROF_MSG_ENC_NONE); privwin_outgoing_msg(privwin, plugin_msg); - free(id); plugins_post_priv_message_send(privwin->fulljid, plugin_msg); - - free(plugin_msg); - jid_destroy(jidp); } } diff --git a/src/event/server_events.c b/src/event/server_events.c index 0ff3e5db..cdb0a983 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -151,11 +151,10 @@ sv_ev_roster_received(void) // check pgp key valid if specified ProfAccount* account = accounts_get_account(account_name); if (account && account->pgp_keyid) { - char* err_str = NULL; + auto_char char* err_str = NULL; if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { cons_show_error("Invalid PGP key ID specified: %s, %s", account->pgp_keyid, err_str); } - free(err_str); // Redraw the screen after entry of the PGP secret key, but not init ProfWin* win = wins_get_current(); @@ -633,13 +632,12 @@ sv_ev_incoming_message(ProfMessage* message) char* looking_for_jid = message->from_jid->barejid; if (message->is_mam) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) { if (message->to_jid) { looking_for_jid = message->to_jid->barejid; } } - free(mybarejid); } chatwin = wins_get_chat(looking_for_jid); @@ -1106,14 +1104,13 @@ sv_ev_muc_occupant_online(const char* const room, const char* const nick, const } // handle nickname change - char* old_nick = muc_roster_nick_change_complete(room, nick); + auto_char char* old_nick = muc_roster_nick_change_complete(room, nick); if (old_nick) { ProfMucWin* mucwin = wins_get_muc(room); if (mucwin) { mucwin_occupant_nick_change(mucwin, old_nick, nick); wins_private_nick_change(mucwin->roomjid, old_nick, nick); } - free(old_nick); occupantswin_occupants(room); rosterwin_roster(); @@ -1199,7 +1196,7 @@ sv_ev_certfail(const char* const errormsg, const TLSCertificate* cert) cons_show(""); ui_update(); - char* cmd = ui_get_line(); + auto_char char* cmd = ui_get_line(); while ((g_strcmp0(cmd, "/tls allow") != 0) && (g_strcmp0(cmd, "/tls always") != 0) @@ -1217,7 +1214,6 @@ sv_ev_certfail(const char* const errormsg, const TLSCertificate* cert) if (g_strcmp0(cmd, "/tls allow") == 0) { cons_show("Continuing with connection."); tlscerts_set_current(cert->fingerprint); - free(cmd); return 1; } else if (g_strcmp0(cmd, "/tls always") == 0) { cons_show("Adding %s to trusted certificates.", cert->fingerprint); @@ -1225,17 +1221,14 @@ sv_ev_certfail(const char* const errormsg, const TLSCertificate* cert) tlscerts_add(cert); cafile_add(cert); } - free(cmd); return 1; } else if (g_strcmp0(cmd, "/quit") == 0) { prof_set_quit(); - free(cmd); - return 0; - } else { - cons_show("Aborting connection."); - free(cmd); return 0; } + + cons_show("Aborting connection."); + return 0; } void @@ -1313,7 +1306,7 @@ sv_ev_bookmark_autojoin(Bookmark* bookmark) return; } - char* nick = NULL; + auto_char char* nick = NULL; if (bookmark->nick) { nick = strdup(bookmark->nick); @@ -1332,8 +1325,6 @@ sv_ev_bookmark_autojoin(Bookmark* bookmark) iq_room_affiliation_list(bookmark->barejid, "admin", false); iq_room_affiliation_list(bookmark->barejid, "owner", false); } - - free(nick); } static void diff --git a/src/log.c b/src/log.c index f2537675..734799b3 100644 --- a/src/log.c +++ b/src/log.c @@ -73,9 +73,9 @@ enum { static void _rotate_log_file(void) { - gchar* log_file = g_strdup(mainlogfile); + auto_gchar gchar* log_file = g_strdup(mainlogfile); size_t len = strlen(log_file); - gchar* log_file_new = malloc(len + 5); + auto_gchar gchar* log_file_new = malloc(len + 5); // the mainlog file should always end in '.log', lets remove this last part // so that we can have profanity.001.log later @@ -100,8 +100,6 @@ _rotate_log_file(void) log_init(log_get_filter(), NULL); - free(log_file_new); - free(log_file); log_info("Log has been rotated"); } diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 66081574..0dfc6f96 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -392,12 +392,10 @@ omemo_publish_crypto_materials(void) static void _acquire_sender_devices_list(void) { - char* barejid = connection_get_barejid(); + auto_char char* barejid = connection_get_barejid(); g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_own_device_list); omemo_devicelist_request(barejid); - - free(barejid); } void @@ -430,11 +428,10 @@ omemo_start_session(const char* const barejid) log_debug("[OMEMO] missing device list for %s", barejid); // Own devices are handled by _handle_own_device_list // We won't add _handle_device_list_start_session for ourself - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); if (g_strcmp0(mybarejid, barejid) != 0) { g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_device_list_start_session); } - free(mybarejid); omemo_devicelist_request(barejid); return; } @@ -689,10 +686,9 @@ omemo_start_device_session(const char* const jid, uint32_t device_id, auto_gchar gchar* trust_mode = prefs_get_string(PREF_OMEMO_TRUST_MODE); if ((g_strcmp0(trust_mode, "blind") == 0) && !trusted) { - char* fp = _omemo_fingerprint(identity_key, TRUE); + auto_char char* fp = _omemo_fingerprint(identity_key, TRUE); cons_show("Blind trust for %s device %d (%s)", jid, device_id, fp); omemo_trust(jid, fp); - free(fp); trusted = TRUE; } diff --git a/src/otr/otr.c b/src/otr/otr.c index bd2674aa..bc2c042e 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -122,15 +122,14 @@ static void cb_inject_message(void* opdata, const char* accountname, const char* protocol, const char* recipient, const char* message) { - char* id = message_send_chat_otr(recipient, message, FALSE, NULL); - free(id); + free(message_send_chat_otr(recipient, message, FALSE, NULL)); } static void cb_write_fingerprints(void* opdata) { gcry_error_t err = 0; - gchar* fpsfilename = files_file_in_account_data_path(DIR_OTR, jid, "fingerprints.txt"); + auto_gchar gchar* fpsfilename = files_file_in_account_data_path(DIR_OTR, jid, "fingerprints.txt"); if (!fpsfilename) { log_error("Failed to create fingerprints file"); cons_show_error("Failed to create fingerprints file"); @@ -142,8 +141,6 @@ cb_write_fingerprints(void* opdata) log_error("Failed to write fingerprints file"); cons_show_error("Failed to write fingerprints file"); } - - g_free(fpsfilename); } static void @@ -305,8 +302,7 @@ otr_on_message_recv(const char* const barejid, const char* const resource, const memmove(whitespace_base, whitespace_base + tag_length, tag_length); char* otr_query_message = otr_start_query(); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session…"); - char* id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); - free(id); + free(message_send_chat_otr(barejid, otr_query_message, FALSE, NULL)); } } } @@ -319,8 +315,7 @@ otr_on_message_recv(const char* const barejid, const char* const resource, const if (policy == PROF_OTRPOLICY_ALWAYS && *decrypted == FALSE && !whitespace_base) { char* otr_query_message = otr_start_query(); cons_show("Attempting to start OTR session…"); - char* id = message_send_chat_otr(barejid, otr_query_message, FALSE, NULL); - free(id); + free(message_send_chat_otr(barejid, otr_query_message, FALSE, NULL)); } return newmessage; @@ -329,7 +324,7 @@ otr_on_message_recv(const char* const barejid, const char* const resource, const gboolean otr_on_message_send(ProfChatWin* chatwin, const char* const message, gboolean request_receipt, const char* const replace_id) { - char* id = NULL; + auto_char char* id = NULL; prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); // Send encrypted message @@ -341,7 +336,6 @@ otr_on_message_send(ProfChatWin* chatwin, const char* const message, gboolean re log_database_add_outgoing_chat(id, chatwin->barejid, message, replace_id, PROF_MSG_ENC_OTR); chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_ENC_OTR, request_receipt, replace_id); otr_free_message(encrypted); - free(id); return TRUE; } else { win_println((ProfWin*)chatwin, THEME_ERROR, "-", "%s", "Failed to encrypt and send message."); @@ -357,12 +351,10 @@ otr_on_message_send(ProfChatWin* chatwin, const char* const message, gboolean re // tag and send for policy opportunistic if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - char* otr_tagged_msg = otr_tag_message(message); + auto_char char* otr_tagged_msg = otr_tag_message(message); id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg, request_receipt, replace_id); chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_ENC_NONE, request_receipt, replace_id); chat_log_msg_out(chatwin->barejid, message, NULL); - free(otr_tagged_msg); - free(id); return TRUE; } diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c index 09bcdadc..d2454665 100644 --- a/src/pgp/gpg.c +++ b/src/pgp/gpg.c @@ -94,10 +94,9 @@ _p_gpg_passphrase_cb(void* hook, const char* uid_hint, const char* passphrase_in } else { GString* pass_term = g_string_new(""); - char* password = ui_ask_pgp_passphrase(uid_hint, prev_was_bad); + auto_char char* password = ui_ask_pgp_passphrase(uid_hint, prev_was_bad); if (password) { g_string_append(pass_term, password); - free(password); } g_string_append(pass_term, "\n"); @@ -462,10 +461,9 @@ p_gpg_verify(const char* const barejid, const char* const sign) return; } - char* sign_with_header_footer = _add_header_footer(sign, PGP_SIGNATURE_HEADER, PGP_SIGNATURE_FOOTER); + auto_char char* sign_with_header_footer = _add_header_footer(sign, PGP_SIGNATURE_HEADER, PGP_SIGNATURE_FOOTER); gpgme_data_t sign_data; gpgme_data_new_from_mem(&sign_data, sign_with_header_footer, strlen(sign_with_header_footer), 1); - free(sign_with_header_footer); gpgme_data_t plain_data; gpgme_data_new(&plain_data); @@ -533,7 +531,7 @@ p_gpg_sign(const char* const str, const char* const fp) return NULL; } - char* str_or_empty = NULL; + auto_char char* str_or_empty = NULL; if (str) { str_or_empty = strdup(str); } else { @@ -541,7 +539,6 @@ p_gpg_sign(const char* const str, const char* const fp) } gpgme_data_t str_data; gpgme_data_new_from_mem(&str_data, str_or_empty, strlen(str_or_empty), 1); - free(str_or_empty); gpgme_data_t signed_data; gpgme_data_new(&signed_data); @@ -664,10 +661,9 @@ p_gpg_decrypt(const char* const cipher) gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL); - char* cipher_with_headers = _add_header_footer(cipher, PGP_MESSAGE_HEADER, PGP_MESSAGE_FOOTER); + auto_char char* cipher_with_headers = _add_header_footer(cipher, PGP_MESSAGE_HEADER, PGP_MESSAGE_FOOTER); gpgme_data_t cipher_data; gpgme_data_new_from_mem(&cipher_data, cipher_with_headers, strlen(cipher_with_headers), 1); - free(cipher_with_headers); gpgme_data_t plain_data; gpgme_data_new(&plain_data); diff --git a/src/plugins/api.c b/src/plugins/api.c index de286d96..31db05e3 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -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; } diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 8daf633d..60fd3263 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -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 diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index a9e98e12..f2fc7086 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -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); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 580f98f0..f24f8b34 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -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; } diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index cf1e4a87..43e37e6a 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -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(); } diff --git a/src/plugins/settings.c b/src/plugins/settings.c index 2b99c9cf..1d0c636c 100644 --- a/src/plugins/settings.c +++ b/src/plugins/settings.c @@ -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); } diff --git a/src/plugins/themes.c b/src/plugins/themes.c index 98139453..bda8629c 100644 --- a/src/plugins/themes.c +++ b/src/plugins/themes.c @@ -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 diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 8c7818e7..ebbce5e3 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -114,8 +114,8 @@ autocomplete_length(Autocomplete ac) void autocomplete_update(Autocomplete ac, char** items) { - gchar* last_found = NULL; - gchar* search_str = NULL; + auto_gchar gchar* last_found = NULL; + auto_gchar gchar* search_str = NULL; if (ac->last_found) { last_found = strdup(ac->last_found->data); @@ -131,12 +131,10 @@ autocomplete_update(Autocomplete ac, char** items) if (last_found) { // NULL if last_found was removed on update. ac->last_found = g_list_find_custom(ac->items, last_found, (GCompareFunc)strcmp); - free(last_found); } if (search_str) { ac->search_str = strdup(search_str); - free(search_str); } } diff --git a/src/tools/bookmark_ignore.c b/src/tools/bookmark_ignore.c index 613a956f..9355deb1 100644 --- a/src/tools/bookmark_ignore.c +++ b/src/tools/bookmark_ignore.c @@ -52,9 +52,7 @@ static gchar* account_jid = NULL; static void _bookmark_ignore_load() { - gchar* bi_loc; - - bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE); + auto_gchar gchar* bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE); if (g_file_test(bi_loc, G_FILE_TEST_EXISTS)) { g_chmod(bi_loc, S_IRUSR | S_IWUSR); @@ -62,24 +60,18 @@ _bookmark_ignore_load() bookmark_ignore_keyfile = g_key_file_new(); g_key_file_load_from_file(bookmark_ignore_keyfile, bi_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); - - g_free(bi_loc); } static void _bookmark_save() { gsize g_data_size; - gchar* g_bookmark_ignore_data = g_key_file_to_data(bookmark_ignore_keyfile, &g_data_size, NULL); + auto_gchar gchar* g_bookmark_ignore_data = g_key_file_to_data(bookmark_ignore_keyfile, &g_data_size, NULL); - gchar* bi_loc; - bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE); + auto_gchar gchar* bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE); g_file_set_contents(bi_loc, g_bookmark_ignore_data, g_data_size, NULL); g_chmod(bi_loc, S_IRUSR | S_IWUSR); - - g_free(bi_loc); - g_free(g_bookmark_ignore_data); } void diff --git a/src/tools/http_upload.c b/src/tools/http_upload.c index 71d42bff..8be56009 100644 --- a/src/tools/http_upload.c +++ b/src/tools/http_upload.c @@ -163,7 +163,7 @@ http_file_put(void* userdata) FILE* fh = NULL; - char* err = NULL; + auto_char char* err = NULL; gchar* content_type_header; // Optional headers gchar* auth_header = NULL; @@ -318,7 +318,6 @@ http_file_put(void* userdata) } cons_show_error(msg); g_free(msg); - free(err); } else { if (!upload->cancel) { msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename); diff --git a/src/tools/parser.c b/src/tools/parser.c index 93c765f5..d62e79f8 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -51,7 +51,7 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb } // copy and strip input of leading/trailing whitespace - char* copy = strdup(inp); + auto_char char* copy = strdup(inp); g_strstrip(copy); int inp_size = g_utf8_strlen(copy, -1); @@ -135,8 +135,6 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); } - free(copy); - int num = g_slist_length(tokens) - 1; // if num args not valid return NULL diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 54b4151b..d462f08a 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -329,13 +329,12 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr int num = wins_get_num(window); auto_gchar gchar* display_name; - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) { display_name = strdup("me"); } else { display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart); } - free(mybarejid); #ifdef HAVE_LIBGPGME if (prefs_get_boolean(PREF_PGP_PUBKEY_AUTOIMPORT)) { @@ -431,7 +430,7 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id, ProfWin* window = (ProfWin*)chatwin; wins_add_quotes_ac(window, message, FALSE); - char* enc_char; + auto_char char* enc_char; if (chatwin->outgoing_char) { enc_char = chatwin->outgoing_char; } else if (enc_mode == PROF_MSG_ENC_OTR) { @@ -452,8 +451,6 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id, win_print_outgoing((ProfWin*)chatwin, enc_char, id, replace_id, message); } - free(enc_char); - // save last id and message for LMC if (id) { _chatwin_set_last_message(chatwin, id, message); @@ -465,7 +462,7 @@ chatwin_outgoing_carbon(ProfChatWin* chatwin, ProfMessage* message) { assert(chatwin != NULL); - char* enc_char; + auto_char char* enc_char; if (message->enc == PROF_MSG_ENC_PGP) { enc_char = prefs_get_pgp_char(); } else if (message->enc == PROF_MSG_ENC_OMEMO) { @@ -479,8 +476,6 @@ chatwin_outgoing_carbon(ProfChatWin* chatwin, ProfMessage* message) win_print_outgoing(window, enc_char, message->id, message->replace_id, message->plain); int num = wins_get_num(window); status_bar_active(num, WIN_CHAT, chatwin->barejid); - - free(enc_char); } void @@ -490,11 +485,9 @@ chatwin_contact_online(ProfChatWin* chatwin, Resource* resource, GDateTime* last const char* show = string_from_resource_presence(resource->presence); PContact contact = roster_get_contact(chatwin->barejid); - char* display_str = p_contact_create_display_string(contact, resource->name); + auto_char char* display_str = p_contact_create_display_string(contact, resource->name); win_show_status_string((ProfWin*)chatwin, display_str, show, resource->status, last_activity, "++", "online"); - - free(display_str); } void @@ -503,11 +496,9 @@ chatwin_contact_offline(ProfChatWin* chatwin, char* resource, char* status) assert(chatwin != NULL); PContact contact = roster_get_contact(chatwin->barejid); - char* display_str = p_contact_create_display_string(contact, resource); + auto_char char* display_str = p_contact_create_display_string(contact, resource); win_show_status_string((ProfWin*)chatwin, display_str, "offline", status, NULL, "--", "offline"); - - free(display_str); } char* diff --git a/src/ui/console.c b/src/ui/console.c index a8ccf3eb..fb3f0ad1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -337,9 +337,8 @@ cons_show_incoming_room_message(const char* const nick, const char* const room, if (mention) { win_println(console, THEME_MENTION, "-", "<< room mention: %s in %s (win %d)", nick, room, ui_index); } else if (triggers) { - char* triggers_str = _room_triggers_to_string(triggers); + auto_char char* triggers_str = _room_triggers_to_string(triggers); win_println(console, THEME_TRIGGER, "-", "<< room trigger %s: %s in %s (win %d)", triggers_str, nick, room, ui_index); - free(triggers_str); } else { // 'all' or 'first' if its the first message if ((g_strcmp0(muc_show, "all") == 0) || ((g_strcmp0(muc_show, "first") == 0) && (unread == 0))) { @@ -387,7 +386,7 @@ cons_show_incoming_private_message(const char* const nick, const char* const roo static void _cons_welcome_first_start(void) { - gchar* ident_loc = files_get_data_path(FILE_PROFANITY_IDENTIFIER); + auto_gchar gchar* ident_loc = files_get_data_path(FILE_PROFANITY_IDENTIFIER); if (!g_file_test(ident_loc, G_FILE_TEST_EXISTS)) { ProfWin* console = wins_get_console(); win_println(console, THEME_DEFAULT, "-", "This seems to be your first time starting Profanity."); @@ -402,7 +401,6 @@ _cons_welcome_first_start(void) win_println(console, THEME_DEFAULT, "-", "/register myjid myserver.org"); win_println(console, THEME_DEFAULT, "-", ""); } - g_free(ident_loc); } void @@ -452,26 +450,27 @@ void cons_check_version(gboolean not_available_msg) { ProfWin* console = wins_get_console(); - char* latest_release = release_get_latest(); + auto_char char* latest_release = release_get_latest(); - if (latest_release) { - gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + if (!latest_release) { + return; + } - if (relase_valid) { - if (release_is_new(latest_release)) { - win_println(console, THEME_DEFAULT, "-", "A new version of Profanity is available: %s", latest_release); - win_println(console, THEME_DEFAULT, "-", "Check for details."); + gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + + if (relase_valid) { + if (release_is_new(latest_release)) { + win_println(console, THEME_DEFAULT, "-", "A new version of Profanity is available: %s", latest_release); + win_println(console, THEME_DEFAULT, "-", "Check for details."); + win_println(console, THEME_DEFAULT, "-", ""); + } else { + if (not_available_msg) { + win_println(console, THEME_DEFAULT, "-", "No new version available."); win_println(console, THEME_DEFAULT, "-", ""); - } else { - if (not_available_msg) { - win_println(console, THEME_DEFAULT, "-", "No new version available."); - win_println(console, THEME_DEFAULT, "-", ""); - } } - - cons_alert(NULL); } - free(latest_release); + + cons_alert(NULL); } } @@ -894,12 +893,10 @@ cons_show_qrcode(const char* const text) ProfWin* console = wins_get_console(); - char* buf = calloc((width * 4) + 1, 1); - char* pad = calloc((width * 4) + 5, 1); + auto_char char* buf = calloc((width * 4) + 1, 1); + auto_char char* pad = calloc((width * 4) + 5, 1); if (!buf || !pad) { - free(pad); - free(buf); return; } @@ -926,9 +923,6 @@ cons_show_qrcode(const char* const text) win_println(console, THEME_DEFAULT, "", ""); win_println(console, THEME_DEFAULT, "", ""); - free(pad); - free(buf); - QRcode_free(qrcode); #else cons_show("This version of Profanity has not been built with libqrencode"); @@ -953,7 +947,7 @@ cons_show_status(const char* const barejid) void cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason) { - char* display_from = NULL; + auto_char char* display_from = NULL; PContact contact = roster_get_contact(invitor); if (contact) { if (p_contact_name(contact)) { @@ -981,8 +975,6 @@ cons_show_room_invite(const char* const invitor, const char* const room, const c notify_invite(display_from, room, reason); } - free(display_from); - cons_alert(NULL); } @@ -1412,10 +1404,9 @@ cons_occupants_setting(void) else cons_show("Occupants wrap (/occupants) : OFF"); - char* occupants_ch = prefs_get_occupants_char(); + auto_char char* occupants_ch = prefs_get_occupants_char(); if (occupants_ch) { cons_show("Occupants char (/occupants) : %s", occupants_ch); - free(occupants_ch); } else { cons_show("Occupants char (/occupants) : none"); } @@ -1426,10 +1417,9 @@ cons_occupants_setting(void) int size = prefs_get_occupants_size(); cons_show("Occupants size (/occupants) : %d", size); - char* header_ch = prefs_get_occupants_header_char(); + auto_char char* header_ch = prefs_get_occupants_header_char(); if (header_ch) { cons_show("Occupants header char (/occupants) : %s", header_ch); - free(header_ch); } else { cons_show("Occupants header char (/occupants) : none"); } @@ -1544,50 +1534,44 @@ cons_roster_setting(void) else cons_show("Roster offline (/roster) : hide"); - char* header_ch = prefs_get_roster_header_char(); + auto_char char* header_ch = prefs_get_roster_header_char(); if (header_ch) { cons_show("Roster header char (/roster) : %s", header_ch); - free(header_ch); } else { cons_show("Roster header char (/roster) : none"); } - char* contact_ch = prefs_get_roster_contact_char(); + auto_char char* contact_ch = prefs_get_roster_contact_char(); if (contact_ch) { cons_show("Roster contact char (/roster) : %s", contact_ch); - free(contact_ch); } else { cons_show("Roster contact char (/roster) : none"); } - char* resource_ch = prefs_get_roster_resource_char(); + auto_char char* resource_ch = prefs_get_roster_resource_char(); if (resource_ch) { cons_show("Roster resource char (/roster) : %s", resource_ch); - free(resource_ch); } else { cons_show("Roster resource char (/roster) : none"); } - char* room_ch = prefs_get_roster_room_char(); + auto_char char* room_ch = prefs_get_roster_room_char(); if (room_ch) { cons_show("Roster room char (/roster) : %s", room_ch); - free(room_ch); } else { cons_show("Roster room char (/roster) : none"); } - char* room_priv_ch = prefs_get_roster_room_private_char(); + auto_char char* room_priv_ch = prefs_get_roster_room_private_char(); if (room_priv_ch) { cons_show("Roster room private char (/roster) : %s", room_priv_ch); - free(room_priv_ch); } else { cons_show("Roster room private char (/roster) : none"); } - char* private_ch = prefs_get_roster_private_char(); + auto_char char* private_ch = prefs_get_roster_private_char(); if (private_ch) { cons_show("Roster private char (/roster) : %s", private_ch); - free(private_ch); } else { cons_show("Roster private char (/roster) : none"); } @@ -2207,9 +2191,8 @@ cons_correction_setting(void) cons_show("Last Message Correction (XEP-0308) (/correction) : OFF"); } - char* cc = prefs_get_correction_char(); + auto_char char* cc = prefs_get_correction_char(); cons_show("LMC indication char (/correction char) : %s", cc); - free(cc); } void @@ -2303,9 +2286,8 @@ cons_show_otr_prefs(void) cons_show("OTR logging (/otr log) : Redacted"); } - char* ch = prefs_get_otr_char(); + auto_char char* ch = prefs_get_otr_char(); cons_show("OTR char (/otr char) : %s", ch); - free(ch); if (prefs_get_boolean(PREF_OTR_SENDFILE)) { cons_show("Allow sending unencrypted files in an OTR session via /sendfile (/otr sendfile): ON"); @@ -2331,9 +2313,8 @@ cons_show_pgp_prefs(void) cons_show("PGP logging (/pgp log) : Redacted"); } - char* ch = prefs_get_pgp_char(); + auto_char char* ch = prefs_get_pgp_char(); cons_show("PGP char (/pgp char) : %s", ch); - free(ch); if (prefs_get_boolean(PREF_PGP_SENDFILE)) { cons_show("Allow sending unencrypted files via /sendfile while otherwise using PGP (/pgp sendfile): ON"); @@ -2362,9 +2343,8 @@ cons_show_omemo_prefs(void) cons_show("OMEMO logging (/omemo log) : Redacted"); } - char* ch = prefs_get_omemo_char(); + auto_char char* ch = prefs_get_omemo_char(); cons_show("OMEMO char (/omemo char) : %s", ch); - free(ch); cons_alert(NULL); } @@ -2384,9 +2364,8 @@ cons_show_ox_prefs(void) cons_show("OX logging (/ox log) : Redacted"); } - char* ch = prefs_get_ox_char(); + auto_char char* ch = prefs_get_ox_char(); cons_show("OX char (/ox char) : %s", ch); - free(ch); cons_alert(NULL); } @@ -2550,24 +2529,21 @@ void cons_show_contact_online(PContact contact, Resource* resource, GDateTime* last_activity) { const char* show = string_from_resource_presence(resource->presence); - char* display_str = p_contact_create_display_string(contact, resource->name); + auto_char char* display_str = p_contact_create_display_string(contact, resource->name); ProfWin* console = wins_get_console(); win_show_status_string(console, display_str, show, resource->status, last_activity, "++", "online"); - - free(display_str); } void cons_show_contact_offline(PContact contact, char* resource, char* status) { - char* display_str = p_contact_create_display_string(contact, resource); + auto_char char* display_str = p_contact_create_display_string(contact, resource); ProfWin* console = wins_get_console(); win_show_status_string(console, display_str, "offline", status, NULL, "--", "offline"); - free(display_str); } void @@ -2593,7 +2569,7 @@ cons_alert(ProfWin* alert_origin_window) if (current->type != WIN_CONSOLE) { status_bar_new(1, WIN_CONSOLE, "console"); - char* win_name; + auto_char char* win_name; if (alert_origin_window) { win_name = win_to_string(alert_origin_window); } else { @@ -2604,8 +2580,6 @@ cons_alert(ProfWin* alert_origin_window) if (!item) { alert_list = g_list_append(alert_list, g_strdup(win_name)); } - - free(win_name); } } @@ -2942,11 +2916,10 @@ cons_clear_alerts(void) void cons_remove_alert(ProfWin* window) { - char* win_name = win_to_string(window); + auto_char char* win_name = win_to_string(window); GList* item = g_list_find_custom(alert_list, win_name, (GCompareFunc)g_strcmp0); alert_list = g_list_remove_link(alert_list, item); g_list_free_full(item, g_free); - free(win_name); } void diff --git a/src/ui/core.c b/src/ui/core.c index cd74e861..1e289bb0 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -234,8 +234,6 @@ ui_contact_online(char* barejid, Resource* resource, GDateTime* last_activity) // show nothing if (g_strcmp0(p_contact_subscription(contact), "none") == 0) { - free(show_console); - free(show_chat_win); return; } @@ -697,9 +695,8 @@ ui_focus_win(ProfWin* window) } status_bar_current(i); - char* identifier = win_get_tab_identifier(window); + auto_char char* identifier = win_get_tab_identifier(window); status_bar_active(i, window->type, identifier); - free(identifier); } void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 9b652f1c..c56f0185 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -652,33 +652,30 @@ _inp_rl_tab_com_handler(int count, int key, gboolean previous) if (strncmp(rl_line_buffer, "/", 1) == 0) { ProfWin* window = wins_get_current(); - char* result = cmd_ac_complete(window, rl_line_buffer, previous); + auto_char char* result = cmd_ac_complete(window, rl_line_buffer, previous); if (result) { rl_replace_line(result, 1); rl_point = rl_end; - free(result); return 0; } } if (strncmp(rl_line_buffer, ">", 1) == 0) { ProfWin* window = wins_get_current(); - char* result = win_quote_autocomplete(window, rl_line_buffer, previous); + auto_char char* result = win_quote_autocomplete(window, rl_line_buffer, previous); if (result) { rl_replace_line(result, 1); rl_point = rl_end; - free(result); return 0; } } ProfWin* current = wins_get_current(); if (current->type == WIN_MUC) { - char* result = muc_autocomplete(current, rl_line_buffer, previous); + auto_char char* result = muc_autocomplete(current, rl_line_buffer, previous); if (result) { rl_replace_line(result, 1); rl_point = rl_end; - free(result); } } diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index a2c31421..7b1ed94d 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -515,7 +515,7 @@ mucwin_outgoing_msg(ProfMucWin* mucwin, const char* const message, const char* c char* mynick = muc_nick(mucwin->roomjid); // displayed message char - char* ch; + auto_char char* ch; if (mucwin->message_char) { ch = strdup(mucwin->message_char); } else if (enc_mode == PROF_MSG_ENC_OTR) { @@ -531,7 +531,6 @@ mucwin_outgoing_msg(ProfMucWin* mucwin, const char* const message, const char* c } win_print_outgoing_muc_msg(window, ch, mynick, id, replace_id, message); - free(ch); // save last id and message for LMC if (id) { @@ -564,7 +563,7 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList ProfWin* window = (ProfWin*)mucwin; char* mynick = muc_nick(mucwin->roomjid); - char* ch; + auto_char char* ch; if (mucwin->message_char) { ch = strdup(mucwin->message_char); } else if (message->enc == PROF_MSG_ENC_OTR) { @@ -589,8 +588,6 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList } else { win_println_incoming_muc_msg(window, ch, flags, message); } - - free(ch); } void diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 36ed73c4..500867e1 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -255,7 +255,7 @@ notify(const char* const message, int timeout, const char* const category) #ifdef HAVE_OSXNOTIFY GString* notify_command = g_string_new("terminal-notifier -title \"Profanity\" -message '"); - char* escaped_single = str_replace(message, "'", "'\\''"); + auto_char char* escaped_single = str_replace(message, "'", "'\\''"); if (escaped_single[0] == '<') { g_string_append(notify_command, "\\<"); @@ -274,7 +274,6 @@ notify(const char* const message, int timeout, const char* const category) } g_string_append(notify_command, "'"); - free(escaped_single); char* term_name = getenv("TERM_PROGRAM"); char* app_id = NULL; diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 3e5b86bc..0f28efd1 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -77,10 +77,9 @@ _occuptantswin_occupant(ProfLayoutSplit* layout, GList* item, gboolean showjid, GString* msg = g_string_new(spaces->str); - char* ch = prefs_get_occupants_char(); + auto_char char* ch = prefs_get_occupants_char(); if (ch) { g_string_append_printf(msg, "%s", ch); - free(ch); } gboolean wrap = prefs_get_boolean(PREF_OCCUPANTS_WRAP); @@ -131,10 +130,9 @@ occupantswin_occupants(const char* const roomjid) GString* prefix = g_string_new(" "); - char* ch = prefs_get_occupants_header_char(); + auto_char char* ch = prefs_get_occupants_header_char(); if (ch) { g_string_append_printf(prefix, "%s", ch); - free(ch); } if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index bf0ae0d0..e2b0f822 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -307,10 +307,9 @@ _rosterwin_unsubscribed_item(ProfLayoutSplit* layout, ProfChatWin* chatwin) indent--; } } - char* ch = prefs_get_roster_contact_char(); + auto_char char* ch = prefs_get_roster_contact_char(); if (ch) { g_string_append_printf(msg, "%s", ch); - free(ch); } auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); @@ -369,10 +368,9 @@ _rosterwin_contact(ProfLayoutSplit* layout, PContact contact) indent--; } } - char* ch = prefs_get_roster_contact_char(); + auto_char char* ch = prefs_get_roster_contact_char(); if (ch) { g_string_append_printf(msg, "%s", ch); - free(ch); } auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); @@ -519,10 +517,9 @@ _rosterwin_resources(ProfLayoutSplit* layout, PContact contact, int current_inde wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString* msg = g_string_new(""); - char* ch = prefs_get_roster_resource_char(); + auto_char char* ch = prefs_get_roster_resource_char(); if (ch) { g_string_append_printf(msg, "%s", ch); - free(ch); } else { g_string_append(msg, " "); } @@ -581,10 +578,9 @@ _rosterwin_resources(ProfLayoutSplit* layout, PContact contact, int current_inde g_string_append(msg, " "); this_indent--; } - char* ch = prefs_get_roster_resource_char(); + auto_char char* ch = prefs_get_roster_resource_char(); if (ch) { g_string_append_printf(msg, "%s", ch); - free(ch); } g_string_append(msg, resource->name); if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { @@ -741,10 +737,9 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin) indent--; } } - char* ch = prefs_get_roster_room_char(); + auto_char char* ch = prefs_get_roster_room_char(); if (ch) { g_string_append_printf(msg, "%s", ch); - free(ch); } auto_gchar gchar* unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD); @@ -838,10 +833,9 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin) g_string_append_printf(privmsg, "(%d) ", privwin->unread); } - ch = prefs_get_roster_room_private_char(); - if (ch) { - g_string_append_printf(privmsg, "%s", ch); - free(ch); + auto_char char* ch2 = prefs_get_roster_room_private_char(); + if (ch2) { + g_string_append_printf(privmsg, "%s", ch2); } char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1; @@ -930,10 +924,9 @@ _rosterwin_private_chats(ProfLayoutSplit* layout, GList* orphaned_privchats) g_string_append_printf(privmsg, "(%d) ", privwin->unread); } - char* ch = prefs_get_roster_private_char(); + auto_char char* ch = prefs_get_roster_private_char(); if (ch) { g_string_append_printf(privmsg, "%s", ch); - free(ch); } g_string_append(privmsg, privwin->fulljid); @@ -1011,10 +1004,9 @@ _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins) win_sub_newline_lazy(layout->subwin); GString* header = g_string_new(" "); - char* ch = prefs_get_roster_header_char(); + auto_char char* ch = prefs_get_roster_header_char(); if (ch) { g_string_append_printf(header, "%s", ch); - free(ch); } g_string_append(header, "Unsubscribed"); @@ -1057,10 +1049,9 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL win_sub_newline_lazy(layout->subwin); GString* header = g_string_new(" "); - char* ch = prefs_get_roster_header_char(); + auto_char char* ch = prefs_get_roster_header_char(); if (ch) { g_string_append_printf(header, "%s", ch); - free(ch); } g_string_append(header, title); @@ -1108,10 +1099,9 @@ _rosterwin_rooms_header(ProfLayoutSplit* layout, GList* rooms, char* title) { win_sub_newline_lazy(layout->subwin); GString* header = g_string_new(" "); - char* ch = prefs_get_roster_header_char(); + auto_char char* ch = prefs_get_roster_header_char(); if (ch) { g_string_append_printf(header, "%s", ch); - free(ch); } g_string_append(header, title); @@ -1170,10 +1160,9 @@ _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs) win_sub_newline_lazy(layout->subwin); GString* title_str = g_string_new(" "); - char* ch = prefs_get_roster_header_char(); + auto_char char* ch = prefs_get_roster_header_char(); if (ch) { g_string_append_printf(title_str, "%s", ch); - free(ch); } g_string_append(title_str, "Private chats"); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index bce773c5..5aceebff 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -433,10 +433,9 @@ _status_bar_draw_tab(StatusBarTab* tab, int pos, int num) pos++; } if (show_name) { - char* display_name = _display_name(tab); + auto_char char* display_name = _display_name(tab); mvwprintw(statusbar_win, 0, pos, "%s", display_name); pos += utf8_display_len(display_name); - free(display_name); } wattroff(statusbar_win, status_attrs); @@ -606,10 +605,9 @@ _tabs_width(void) if (!show_read && !is_current && !tab->highlight) continue; - char* display_name = _display_name(tab); + auto_char char* display_name = _display_name(tab); width += utf8_display_len(display_name); width += 4; - free(display_name); } } return width; @@ -625,10 +623,9 @@ _tabs_width(void) if (!show_read && !is_current && !tab->highlight) continue; - char* display_name = _display_name(tab); + auto_char char* display_name = _display_name(tab); width += utf8_display_len(display_name); width += 2; - free(display_name); } } return width; @@ -710,10 +707,9 @@ _display_name(StatusBarTab* tab) return fullname; } - gchar* trimmed = g_utf8_substring(fullname, 0, tablen); - free(fullname); + auto_gchar gchar* trimmed = g_utf8_substring(fullname, 0, tablen); char* trimmedname = strdup(trimmed); - g_free(trimmed); + free(fullname); return trimmedname; } diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 89469464..ad5986de 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -195,13 +195,11 @@ _title_bar_draw(void) waddch(win, ' '); } - char* title = win_get_title(current); + auto_char char* title = win_get_title(current); mvwprintw(win, 0, 0, " %s", title); pos = strlen(title) + 1; - free(title); - // presence is written from the right side // calculate it first so we have a maxposition maxrightpos = _calc_self_presence(); diff --git a/src/ui/vcardwin.c b/src/ui/vcardwin.c index a49f240c..2a2fdd78 100644 --- a/src/ui/vcardwin.c +++ b/src/ui/vcardwin.c @@ -53,14 +53,13 @@ char* vcardwin_get_string(ProfVcardWin* vcardwin) { GString* string = g_string_new("vCard: "); - char* jid = connection_get_barejid(); + auto_char char* jid = connection_get_barejid(); g_string_append(string, jid); if (vcardwin->vcard && vcardwin->vcard->modified) { g_string_append(string, " (modified)"); } - free(jid); return g_string_free(string, FALSE); } diff --git a/src/ui/window.c b/src/ui/window.c index d705e029..d0ed6704 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -387,7 +387,7 @@ win_get_title(ProfWin* window) assert(vcardwin->memcheck == PROFVCARDWIN_MEMCHECK); GString* title = g_string_new("vCard "); - char* jid = connection_get_barejid(); + auto_char char* jid = connection_get_barejid(); g_string_append(title, jid); @@ -395,7 +395,6 @@ win_get_title(ProfWin* window) g_string_append(title, " *"); } - free(jid); return g_string_free(title, FALSE); } } @@ -1207,11 +1206,10 @@ win_show_vcard(ProfWin* window, vCard* vcard) case VCARD_BIRTHDAY: { auto_gchar gchar* date_format = prefs_get_string(PREF_TIME_VCARD); - gchar* date = g_date_time_format(element->birthday, date_format); + auto_gchar gchar* date = g_date_time_format(element->birthday, date_format); assert(date != NULL); win_println(window, THEME_DEFAULT, "!", "[%d] Birthday: %s", index, date); - g_free(date); break; } case VCARD_ADDRESS: @@ -1336,14 +1334,12 @@ win_show_status_string(ProfWin* window, const char* const from, win_append(window, presence_colour, " is %s", default_show); if (last_activity) { - gchar* date_fmt = NULL; + auto_gchar gchar* date_fmt = NULL; auto_gchar gchar* time_pref = prefs_get_string(PREF_TIME_LASTACTIVITY); date_fmt = g_date_time_format(last_activity, time_pref); assert(date_fmt != NULL); win_append(window, presence_colour, ", last activity: %s", date_fmt); - - g_free(date_fmt); } if (status) @@ -1406,7 +1402,7 @@ win_print_incoming(ProfWin* window, const char* const display_name_from, ProfMes switch (window->type) { case WIN_CHAT: { - char* enc_char; + auto_char char* enc_char; ProfChatWin* chatwin = (ProfChatWin*)window; if (chatwin->incoming_char) { @@ -1431,8 +1427,6 @@ win_print_incoming(ProfWin* window, const char* const display_name_from, ProfMes _win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->from_jid->barejid, message->id, "%s", message->plain); } } - - free(enc_char); break; } case WIN_PRIVATE: @@ -1926,7 +1920,7 @@ _win_print_wrapped(WINDOW* win, const char* const message, size_t indent, int pa { int starty = getcury(win); int wordi = 0; - char* word = malloc(strlen(message) + 1); + auto_char char* word = malloc(strlen(message) + 1); gchar* curr_ch = g_utf8_offset_to_pointer(message, 0); @@ -2033,8 +2027,6 @@ _win_print_wrapped(WINDOW* win, const char* const message, size_t indent, int pa curr_ch = g_utf8_next_char(curr_ch); } } - - free(word); } void diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 0a96b461..4cb84a5a 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -949,13 +949,12 @@ wins_swap(int source_win, int target_win) g_hash_table_steal(windows, GINT_TO_POINTER(source_win)); g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); status_bar_inactive(source_win); - char* identifier = win_get_tab_identifier(source); + auto_char char* identifier = win_get_tab_identifier(source); if (win_unread(source) > 0) { status_bar_new(target_win, source->type, identifier); } else { status_bar_active(target_win, source->type, identifier); } - free(identifier); if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); ui_focus_win(console); @@ -967,8 +966,8 @@ wins_swap(int source_win, int target_win) g_hash_table_steal(windows, GINT_TO_POINTER(target_win)); g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target); g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); - char* source_identifier = win_get_tab_identifier(source); - char* target_identifier = win_get_tab_identifier(target); + auto_char char* source_identifier = win_get_tab_identifier(source); + auto_char char* target_identifier = win_get_tab_identifier(target); if (win_unread(source) > 0) { status_bar_new(target_win, source->type, source_identifier); } else { @@ -979,8 +978,6 @@ wins_swap(int source_win, int target_win) } else { status_bar_active(source_win, target->type, target_identifier); } - free(source_identifier); - free(target_identifier); if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { ui_focus_win(console); } @@ -1088,7 +1085,7 @@ wins_tidy(void) GList* curr = keys; while (curr) { ProfWin* window = g_hash_table_lookup(windows, curr->data); - char* identifier = win_get_tab_identifier(window); + auto_char char* identifier = win_get_tab_identifier(window); g_hash_table_steal(windows, curr->data); if (num == 10) { g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window); @@ -1105,7 +1102,6 @@ wins_tidy(void) status_bar_active(num, window->type, identifier); } } - free(identifier); num++; curr = g_list_next(curr); } @@ -1142,14 +1138,13 @@ wins_create_summary(gboolean unread) GString* line = g_string_new(""); int ui_index = GPOINTER_TO_INT(curr->data); - char* winstring = win_to_string(window); + auto_char char* winstring = win_to_string(window); if (!winstring) { g_string_free(line, TRUE); continue; } g_string_append_printf(line, "%d: %s", ui_index, winstring); - free(winstring); result = g_slist_append(result, strdup(line->str)); g_string_free(line, TRUE); @@ -1188,14 +1183,13 @@ wins_create_summary_attention() GString* line = g_string_new(""); int ui_index = GPOINTER_TO_INT(curr->data); - char* winstring = win_to_string(window); + auto_char char* winstring = win_to_string(window); if (!winstring) { g_string_free(line, TRUE); continue; } g_string_append_printf(line, "%d: %s", ui_index, winstring); - free(winstring); result = g_slist_append(result, strdup(line->str)); g_string_free(line, TRUE); diff --git a/src/xmpp/avatar.c b/src/xmpp/avatar.c index 3c5ae70d..b7042e13 100644 --- a/src/xmpp/avatar.c +++ b/src/xmpp/avatar.c @@ -100,7 +100,7 @@ avatar_pep_subscribe(void) gboolean avatar_set(const char* path) { - char* expanded_path = get_expanded_path(path); + auto_char char* expanded_path = get_expanded_path(path); GError* err = NULL; GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(expanded_path, &err); @@ -109,7 +109,6 @@ avatar_set(const char* path) cons_show_error("An error occurred while opening %s: %s.", expanded_path, err ? err->message : "No error message given"); return FALSE; } - free(expanded_path); // Scale img int w = gdk_pixbuf_get_width(pixbuf); @@ -127,7 +126,7 @@ avatar_set(const char* path) pixbuf = new_pixbuf; } - gchar* img_data; + auto_gchar gchar* img_data; gsize len = -1; if (!gdk_pixbuf_save_to_buffer(pixbuf, &img_data, &len, "png", &err, NULL)) { @@ -141,7 +140,6 @@ avatar_set(const char* path) xmpp_stanza_release(iq); iq = stanza_create_avatar_metadata_publish_iq(ctx, img_data, len, gdk_pixbuf_get_height(pixbuf), gdk_pixbuf_get_width(pixbuf)); - free(img_data); g_object_unref(pixbuf); iq_send_stanza(iq); xmpp_stanza_release(iq); @@ -252,13 +250,11 @@ _avatar_request_item_by_id(const char* jid, avatar_metadata* data) xmpp_ctx_t* const ctx = connection_get_ctx(); - char* uid = connection_create_stanza_id(); + auto_char char* uid = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_avatar_retrieve_data_request(ctx, uid, data->id, jid); iq_id_handler_add(uid, _avatar_request_item_result_handler, (ProfIqFreeCallback)_free_avatar_data, data); - free(uid); - iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -297,18 +293,16 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use return 1; } - char* buf = xmpp_stanza_get_text(st_data); + auto_char char* buf = xmpp_stanza_get_text(st_data); if (!buf) { return 1; } gsize size; - gchar* de = (gchar*)g_base64_decode(buf, &size); - free(buf); + auto_gchar gchar* de = (gchar*)g_base64_decode(buf, &size); - char* path = files_get_data_path(""); + auto_gchar gchar* path = files_get_data_path(""); GString* filename = g_string_new(path); - free(path); g_string_append(filename, "avatars/"); @@ -323,7 +317,7 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use } } - gchar* from = str_replace(from_attr, "@", "_at_"); + auto_gchar gchar* from = str_replace(from_attr, "@", "_at_"); g_string_append(filename, from); avatar_metadata* data = (avatar_metadata*)userdata; @@ -340,8 +334,6 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use g_string_append(filename, ".webp"); } - free(from); - GError* err = NULL; if (g_file_set_contents(filename->str, de, size, &err) == FALSE) { log_error("Unable to save picture: %s", err->message); @@ -371,7 +363,6 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use } g_string_free(filename, TRUE); - free(de); return 1; } diff --git a/src/xmpp/blocking.c b/src/xmpp/blocking.c index e68999d2..0e8c215f 100644 --- a/src/xmpp/blocking.c +++ b/src/xmpp/blocking.c @@ -70,13 +70,12 @@ blocking_request(void) } blocked_ac = autocomplete_new(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); iq_id_handler_add(id, _blocklist_result_handler, NULL, NULL); xmpp_ctx_t* ctx = connection_get_ctx(); xmpp_stanza_t* iq = stanza_create_blocked_list_request(ctx); xmpp_stanza_set_id(iq, id); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); @@ -112,7 +111,7 @@ blocked_add(char* jid, blocked_report reportkind, const char* const message) xmpp_ctx_t* ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); xmpp_stanza_t* block = xmpp_stanza_new(ctx); @@ -156,7 +155,6 @@ blocked_add(char* jid, blocked_report reportkind, const char* const message) xmpp_stanza_release(block); iq_id_handler_add(id, _block_add_result_handler, free, strdup(jid)); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); @@ -174,7 +172,7 @@ blocked_remove(char* jid) xmpp_ctx_t* ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); xmpp_stanza_t* block = xmpp_stanza_new(ctx); @@ -192,7 +190,6 @@ blocked_remove(char* jid) xmpp_stanza_release(block); iq_id_handler_add(id, _block_remove_result_handler, free, strdup(jid)); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 916c8195..d3ab2eb7 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -312,13 +312,12 @@ _bookmark_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata) int minimize = 0; xmpp_stanza_t* minimize_st = xmpp_stanza_get_child_by_name_and_ns(child, STANZA_NAME_MINIMIZE, STANZA_NS_EXT_GAJIM_BOOKMARKS); if (minimize_st) { - char* min_str = xmpp_stanza_get_text(minimize_st); + auto_char char* min_str = xmpp_stanza_get_text(minimize_st); if (strcmp(min_str, "true") == 0) { minimize = 1; } else if (strcmp(min_str, "false") == 0) { minimize = 2; } - free(min_str); } autocomplete_add(bookmark_ac, barejid); @@ -364,9 +363,8 @@ _send_bookmarks(void) { xmpp_ctx_t* ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 3bd567cd..071016a6 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -58,7 +58,7 @@ #include "xmpp/form.h" #include "xmpp/capabilities.h" -static char* cache_loc; +static gchar* cache_loc; static GKeyFile* cache; static GHashTable* jid_to_ver; @@ -355,7 +355,7 @@ caps_close(void) cache = NULL; g_hash_table_destroy(jid_to_ver); g_hash_table_destroy(jid_to_caps); - free(cache_loc); + g_free(cache_loc); cache_loc = NULL; g_hash_table_destroy(prof_features); prof_features = NULL; diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 2a022cc4..a992591f 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -238,10 +238,9 @@ _conn_apply_settings(const char* const jid, const char* const passwd, const char return FALSE; } - char* cert_path = prefs_get_tls_certpath(); + auto_char char* cert_path = prefs_get_tls_certpath(); if (cert_path) { xmpp_conn_set_capath(conn.xmpp_conn, cert_path); - free(cert_path); } xmpp_conn_set_certfail_handler(conn.xmpp_conn, _connection_certfail_cb); @@ -734,9 +733,8 @@ connection_get_barejid(void) if (!jid) return NULL; - Jid* jidp = jid_create(jid); + auto_jid Jid* jidp = jid_create(jid); char* result = strdup(jidp->barejid); - jid_destroy(jidp); return result; } @@ -811,18 +809,15 @@ connection_free_uuid(char* uuid) char* connection_create_stanza_id(void) { - char* rndid = get_random_string(CON_RAND_ID_LEN); + auto_char char* rndid = get_random_string(CON_RAND_ID_LEN); assert(rndid != NULL); - gchar* hmac = g_compute_hmac_for_string(G_CHECKSUM_SHA1, - (guchar*)prof_identifier, strlen(prof_identifier), - rndid, strlen(rndid)); + auto_gchar gchar* hmac = g_compute_hmac_for_string(G_CHECKSUM_SHA1, + (guchar*)prof_identifier, strlen(prof_identifier), + rndid, strlen(rndid)); char* ret = g_strdup_printf("%s%s", rndid, hmac); - free(rndid); - g_free(hmac); - return ret; } @@ -1108,11 +1103,9 @@ _xmpp_file_logger(void* const userdata, const xmpp_log_level_t xmpp_level, const static void _random_bytes_init(void) { - char* rndbytes_loc; + auto_gchar gchar* rndbytes_loc = files_get_data_path(FILE_PROFANITY_IDENTIFIER); GKeyFile* rndbytes; - rndbytes_loc = files_get_data_path(FILE_PROFANITY_IDENTIFIER); - if (g_file_test(rndbytes_loc, G_FILE_TEST_EXISTS)) { g_chmod(rndbytes_loc, S_IRUSR | S_IWUSR); } @@ -1127,18 +1120,13 @@ _random_bytes_init(void) g_key_file_set_string(rndbytes, "identifier", "random_bytes", profanity_instance_id); gsize g_data_size; - gchar* g_accounts_data = g_key_file_to_data(rndbytes, &g_data_size, NULL); + auto_gchar gchar* g_accounts_data = g_key_file_to_data(rndbytes, &g_data_size, NULL); - gchar* base = g_path_get_dirname(rndbytes_loc); - gchar* true_loc = get_file_or_linked(rndbytes_loc, base); + auto_gchar gchar* base = g_path_get_dirname(rndbytes_loc); + auto_gchar gchar* true_loc = get_file_or_linked(rndbytes_loc, base); g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL); - - g_free(base); - free(true_loc); - g_free(g_accounts_data); } - free(rndbytes_loc); g_key_file_free(rndbytes); } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 159ba609..3aff1093 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -429,10 +429,9 @@ iq_http_upload_request(HTTPUpload* upload) } xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_http_upload_request(ctx, id, jid, upload); iq_id_handler_add(id, _http_upload_response_id_handler, NULL, upload); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); @@ -444,13 +443,11 @@ void iq_disco_info_request(gchar* jid) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, jid, NULL); iq_id_handler_add(id, _disco_info_response_id_handler, NULL, NULL); - free(id); - iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -459,13 +456,11 @@ void iq_disco_info_request_onconnect(gchar* jid) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, jid, NULL); iq_id_handler_add(id, _disco_info_response_id_handler_onconnect, NULL, NULL); - free(id); - iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -474,13 +469,11 @@ void iq_last_activity_request(gchar* jid) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_last_activity_iq(ctx, id, jid); iq_id_handler_add(id, _last_activity_response_id_handler, NULL, NULL); - free(id); - iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -489,7 +482,7 @@ void iq_room_info_request(const char* const room, gboolean display_result) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, room, NULL); ProfRoomInfoData* cb_data = malloc(sizeof(ProfRoomInfoData)); @@ -502,8 +495,6 @@ iq_room_info_request(const char* const room, gboolean display_result) iq_send_stanza(iq); xmpp_stanza_release(iq); } - - free(id); } void @@ -832,7 +823,7 @@ static void _error_handler(xmpp_stanza_t* const stanza) { const char* id = xmpp_stanza_get_id(stanza); - char* error_msg = stanza_get_error_message(stanza); + auto_char char* error_msg = stanza_get_error_message(stanza); if (id) { log_debug("IQ error handler fired, id: %s, error: %s", id, error_msg); @@ -841,8 +832,6 @@ _error_handler(xmpp_stanza_t* const stanza) log_debug("IQ error handler fired, error: %s", error_msg); log_error("IQ error received, error: %s", error_msg); } - - free(error_msg); } static int @@ -871,9 +860,8 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata) // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_warning("Error received for capabilities response from %s: ", from, error_message); - free(error_message); return 0; } @@ -950,9 +938,8 @@ _caps_response_for_jid_id_handler(xmpp_stanza_t* const stanza, void* const userd // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_warning("Error received for capabilities response from %s: ", from, error_message); - free(error_message); return 0; } @@ -1009,9 +996,8 @@ _caps_response_legacy_id_handler(xmpp_stanza_t* const stanza, void* const userda // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_warning("Error received for capabilities response from %s: ", from, error_message); - free(error_message); return 0; } @@ -1142,7 +1128,7 @@ _command_list_result_handler(xmpp_stanza_t* const stanza, void* const userdata) { const char* id = xmpp_stanza_get_id(stanza); const char* type = xmpp_stanza_get_type(stanza); - char* from = strdup(xmpp_stanza_get_from(stanza)); + auto_char char* from = strdup(xmpp_stanza_get_from(stanza)); if (id) { log_debug("IQ command list result handler fired, id: %s.", id); @@ -1152,14 +1138,12 @@ _command_list_result_handler(xmpp_stanza_t* const stanza, void* const userdata) // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_debug("Error retrieving command list for %s: %s", from, error_message); ProfWin* win = wins_get_by_string(from); if (win) { win_command_list_error(win, error_message); } - free(error_message); - free(from); return 0; } @@ -1187,7 +1171,6 @@ _command_list_result_handler(xmpp_stanza_t* const stanza, void* const userdata) win_handle_command_list(win, cmds); g_slist_free(cmds); - free(from); return 0; } @@ -1215,10 +1198,9 @@ _command_exec_response_handler(xmpp_stanza_t* const stanza, void* const userdata // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_debug("Error executing command %s for %s: %s", command, from, error_message); win_command_exec_error(win, command, error_message); - free(error_message); return 0; } @@ -1321,10 +1303,9 @@ _enable_carbons_id_handler(xmpp_stanza_t* const stanza, void* const userdata) { const char* type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); cons_show_error("Server error enabling message carbons: %s", error_message); log_debug("Error enabling carbons: %s", error_message); - free(error_message); } else { log_debug("Message carbons enabled."); } @@ -1337,10 +1318,9 @@ _disable_carbons_id_handler(xmpp_stanza_t* const stanza, void* const userdata) { const char* type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); cons_show_error("Server error disabling message carbons: %s", error_message); log_debug("Error disabling carbons: %s", error_message); - free(error_message); } else { log_debug("Message carbons disabled."); } @@ -1357,14 +1337,13 @@ _manual_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata) // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); if (!error_message) { cons_show_error("Error returned from pinging %s.", from); } else { cons_show_error("Error returned from pinging %s: %s.", from, error_message); } - free(error_message); return 0; } @@ -1444,9 +1423,8 @@ _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata) } // show warning if error - char* error_msg = stanza_get_error_message(stanza); + auto_char char* error_msg = stanza_get_error_message(stanza); log_warning("Server ping (id=%s) responded with error: %s", id, error_msg); - free(error_msg); // turn off autoping if error type is 'cancel' xmpp_stanza_t* error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); @@ -1483,9 +1461,8 @@ _version_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata) if (g_strcmp0(type, STANZA_TYPE_RESULT) != 0) { if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); ui_handle_software_version_error(from, error_message); - free(error_message); } else { ui_handle_software_version_error(from, "unknown error"); log_error("Software version result with unrecognised type attribute."); @@ -1876,9 +1853,8 @@ _room_config_id_handler(xmpp_stanza_t* const stanza, void* const userdata) // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); ui_handle_room_configuration_form_error(from, error_message); - free(error_message); return 0; } @@ -1932,13 +1908,12 @@ _room_affiliation_set_result_id_handler(xmpp_stanza_t* const stanza, void* const // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation_set->privilege, from, affiliation_set->item, error_message); ProfMucWin* mucwin = wins_get_muc(from); if (mucwin) { mucwin_affiliation_set_error(mucwin, affiliation_set->item, affiliation_set->privilege, error_message); } - free(error_message); } return 0; @@ -1960,13 +1935,12 @@ _room_role_set_result_id_handler(xmpp_stanza_t* const stanza, void* const userda // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_debug("Error setting role %s list for room %s, user %s: %s", role_set->privilege, from, role_set->item, error_message); ProfMucWin* mucwin = wins_get_muc(from); if (mucwin) { mucwin_role_set_error(mucwin, role_set->item, role_set->privilege, error_message); } - free(error_message); } return 0; @@ -1988,13 +1962,12 @@ _room_affiliation_list_result_id_handler(xmpp_stanza_t* const stanza, void* cons // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_debug("Error retrieving %s list for room %s: %s", affiliation_list->affiliation, from, error_message); ProfMucWin* mucwin = wins_get_muc(from); if (mucwin && affiliation_list->show_ui_message) { mucwin_affiliation_list_error(mucwin, affiliation_list->affiliation, error_message); } - free(error_message); return 0; } GSList* jids = NULL; @@ -2045,13 +2018,12 @@ _room_role_list_result_id_handler(xmpp_stanza_t* const stanza, void* const userd // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); log_debug("Error retrieving %s list for room %s: %s", role, from, error_message); ProfMucWin* mucwin = wins_get_muc(from); if (mucwin) { mucwin_role_list_error(mucwin, role, error_message); } - free(error_message); return 0; } GSList* nicks = NULL; @@ -2095,9 +2067,8 @@ _room_config_submit_id_handler(xmpp_stanza_t* const stanza, void* const userdata // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); ui_handle_room_config_submit_result_error(from, error_message); - free(error_message); return 0; } @@ -2123,9 +2094,8 @@ _room_kick_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata) // handle error responses ProfMucWin* mucwin = wins_get_muc(from); if (mucwin && (g_strcmp0(type, STANZA_TYPE_ERROR) == 0)) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); mucwin_kick_error(mucwin, nick, error_message); - free(error_message); } return 0; @@ -2163,9 +2133,8 @@ _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { ProfMucWin* mucwin = wins_get_muc(cb_data->room); if (mucwin && cb_data->display) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); mucwin_room_info_error(mucwin, error_message); - free(error_message); } return 0; } @@ -2256,13 +2225,12 @@ _last_activity_response_id_handler(xmpp_stanza_t* const stanza, void* const user // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); if (from) { cons_show_error("Last activity request failed for %s: %s", from, error_message); } else { cons_show_error("Last activity request failed: %s", error_message); } - free(error_message); return 0; } @@ -2310,13 +2278,12 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); if (from) { cons_show_error("Service discovery failed for %s: %s", from, error_message); } else { cons_show_error("Service discovery failed: %s", error_message); } - free(error_message); return 0; } @@ -2394,13 +2361,12 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* con // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); if (from) { log_error("Service discovery failed for %s: %s", from, error_message); } else { log_error("Service discovery failed: %s", error_message); } - free(error_message); return 0; } @@ -2446,13 +2412,12 @@ _http_upload_response_id_handler(xmpp_stanza_t* const stanza, void* const userda // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); if (from) { cons_show_error("Uploading '%s' failed for %s: %s", upload->filename, from, error_message); } else { cons_show_error("Uploading '%s' failed: %s", upload->filename, error_message); } - free(error_message); return 0; } @@ -2569,10 +2534,9 @@ iq_send_stanza(xmpp_stanza_t* const stanza) xmpp_stanza_to_text(stanza, &text, &text_size); xmpp_conn_t* conn = connection_get_conn(); - char* plugin_text = plugins_on_iq_stanza_send(text); + auto_char char* plugin_text = plugins_on_iq_stanza_send(text); if (plugin_text) { xmpp_send_raw_string(conn, "%s", plugin_text); - free(plugin_text); } else { xmpp_send_raw_string(conn, "%s", text); } @@ -2745,10 +2709,9 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata) { const char* type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); cons_show_error("Server error: %s", error_message); log_debug("MAM Error: %s", error_message); - free(error_message); } else if (g_strcmp0(type, "result") == 0) { xmpp_stanza_t* fin = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_FIN, STANZA_NS_MAM2); if (fin) { @@ -2782,7 +2745,7 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata) if (set) { win_print_loading_history(window); - char* firstid = NULL; + auto_char char* firstid = NULL; xmpp_stanza_t* first = xmpp_stanza_get_child_by_name(set, STANZA_NAME_FIRST); firstid = xmpp_stanza_get_text(first); @@ -2794,7 +2757,6 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata) data->end_datestr = NULL; } xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, data->barejid, data->start_datestr, NULL, firstid, NULL); - free(firstid); MamRsmUserdata* ndata = malloc(sizeof(*ndata)); *ndata = *data; @@ -2833,10 +2795,9 @@ _register_change_password_result_id_handler(xmpp_stanza_t* const stanza, void* c { const char* type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { - char* error_message = stanza_get_error_message(stanza); + auto_char char* error_message = stanza_get_error_message(stanza); cons_show_error("Server error: %s", error_message); log_debug("Password change error: %s", error_message); - free(error_message); } else { cons_show("Password successfully changed."); log_debug("Password successfully changed."); @@ -2884,13 +2845,12 @@ _muc_register_nick_response_handler(xmpp_stanza_t* const stanza, void* const use void iq_submit_muc_register_nick_form(ProfConfWin* confwin) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_stanza_t* iq = stanza_create_muc_register_nick(ctx, id, confwin->roomjid, NULL, confwin->form); iq_id_handler_add(id, _muc_register_nick_response_handler, NULL, NULL); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); @@ -2950,7 +2910,7 @@ iq_muc_register_nick(const char* const roomjid) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); xmpp_stanza_set_to(iq, roomjid); @@ -2961,7 +2921,6 @@ iq_muc_register_nick(const char* const roomjid) xmpp_stanza_add_child(iq, query); iq_id_handler_add(id, _muc_register_nick_handler, NULL, NULL); - free(id); iq_send_stanza(iq); diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index 51c710f1..e2757036 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -111,12 +111,8 @@ jid_create(const gchar* const str) Jid* jid_create_from_bare_and_resource(const char* const barejid, const char* const resource) { - Jid* result; - char* jid = create_fulljid(barejid, resource); - result = jid_create(jid); - free(jid); - - return result; + auto_char char* jid = create_fulljid(barejid, resource); + return jid_create(jid); } void diff --git a/src/xmpp/message.c b/src/xmpp/message.c index a6372c4a..1695c225 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -243,7 +243,7 @@ _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* con if (carbons) { // carbon must come from ourselves - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); const char* const stanza_from = xmpp_stanza_get_from(stanza); if (stanza_from) { @@ -256,8 +256,6 @@ _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* con msg_stanza = _handle_carbons(carbons); } } - - free(mybarejid); } if (msg_stanza) { @@ -425,12 +423,11 @@ message_send_chat(const char* const barejid, const char* const msg, const char* xmpp_ctx_t* const ctx = connection_get_ctx(); const char* state = chat_session_get_state(barejid); - char* jid = chat_session_get_jid(barejid); + auto_char char* jid = chat_session_get_jid(barejid); char* id = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id); xmpp_message_set_body(message, msg); - free(jid); if (state) { stanza_attach_state(ctx, message, state); @@ -460,7 +457,7 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean xmpp_ctx_t* const ctx = connection_get_ctx(); const char* state = chat_session_get_state(barejid); - char* jid = chat_session_get_jid(barejid); + auto_char char* jid = chat_session_get_jid(barejid); char* id = connection_create_stanza_id(); xmpp_stanza_t* message = NULL; @@ -469,7 +466,7 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean ProfAccount* account = accounts_get_account(account_name); if (account->pgp_keyid) { auto_jid Jid* jidp = jid_create(jid); - char* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid); + auto_char char* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid); if (encrypted) { message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id); xmpp_message_set_body(message, "This message is encrypted (XEP-0027)."); @@ -482,7 +479,6 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean xmpp_stanza_release(enc_st); xmpp_stanza_add_child(message, x); xmpp_stanza_release(x); - free(encrypted); } else { message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id); xmpp_message_set_body(message, msg); @@ -497,7 +493,6 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id); xmpp_message_set_body(message, msg); #endif - free(jid); if (state) { stanza_attach_state(ctx, message, state); @@ -586,14 +581,11 @@ message_send_chat_otr(const char* const barejid, const char* const msg, gboolean xmpp_ctx_t* const ctx = connection_get_ctx(); const char* state = chat_session_get_state(barejid); - char* jid = chat_session_get_jid(barejid); char* id = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, barejid, id); xmpp_message_set_body(message, msg); - free(jid); - if (state) { stanza_attach_state(ctx, message, state); } @@ -852,7 +844,7 @@ _handle_error(xmpp_stanza_t* const stanza) } // stanza_get_error never returns NULL - char* err_msg = stanza_get_error_message(stanza); + auto_char char* err_msg = stanza_get_error_message(stanza); GString* log_msg = g_string_new("message stanza error received"); if (id) { @@ -885,8 +877,6 @@ _handle_error(xmpp_stanza_t* const stanza) } ui_handle_recipient_error(jid, err_msg); } - - free(err_msg); } static void @@ -1058,10 +1048,9 @@ _handle_groupchat(xmpp_stanza_t* const stanza) if (code) { // If configuration change notification send disco info to get updated info of the muc - char* disqo_info_id = connection_create_stanza_id(); + auto_char char* disqo_info_id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, disqo_info_id, room_jid, NULL); iq_id_handler_add(disqo_info_id, _room_config_handler, NULL, NULL); - free(disqo_info_id); iq_send_stanza(iq); xmpp_stanza_release(iq); @@ -1181,9 +1170,8 @@ _message_send_receipt(const char* const fulljid, const char* const message_id) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, NULL, fulljid, id); - free(id); xmpp_stanza_t* receipt = xmpp_stanza_new(ctx); xmpp_stanza_set_name(receipt, "received"); @@ -1343,12 +1331,10 @@ _handle_carbons(xmpp_stanza_t* const stanza) } // Eliminate duplicate messages in chat with oneself when another client is sending a message - char* bare_from = xmpp_jid_bare(connection_get_ctx(), xmpp_stanza_get_from(message_stanza)); + auto_char char* bare_from = xmpp_jid_bare(connection_get_ctx(), xmpp_stanza_get_from(message_stanza)); if (g_strcmp0(bare_from, xmpp_stanza_get_to(message_stanza)) == 0) { - free(bare_from); return NULL; } - free(bare_from); return message_stanza; } @@ -1469,7 +1455,7 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c if (message->plain || message->body || message->encrypted) { if (is_carbon) { - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); // if we are the recipient, treat as standard incoming message if (g_strcmp0(mybarejid, message->to_jid->barejid) == 0) { @@ -1478,8 +1464,6 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c } else { sv_ev_outgoing_carbon(message); } - - free(mybarejid); } else { sv_ev_incoming_message(message); _receipt_request_handler(stanza); @@ -1589,10 +1573,9 @@ _send_message_stanza(xmpp_stanza_t* const stanza) xmpp_stanza_to_text(stanza, &text, &text_size); xmpp_conn_t* conn = connection_get_conn(); - char* plugin_text = plugins_on_message_stanza_send(text); + auto_char char* plugin_text = plugins_on_message_stanza_send(text); if (plugin_text) { xmpp_send_raw_string(conn, "%s", plugin_text); - free(plugin_text); } else { xmpp_send_raw_string(conn, "%s", text); } diff --git a/src/xmpp/muc.c b/src/xmpp/muc.c index cf41f58f..0b7c319f 100644 --- a/src/xmpp/muc.c +++ b/src/xmpp/muc.c @@ -885,11 +885,10 @@ muc_members_add(const char* const room, const char* const jid) if (g_hash_table_insert(chat_room->members, strdup(jid), NULL)) { #ifdef HAVE_OMEMO if (chat_room->anonymity_type == MUC_ANONYMITY_TYPE_NONANONYMOUS) { - char* our_barejid = connection_get_barejid(); + auto_char char* our_barejid = connection_get_barejid(); if (strcmp(jid, our_barejid) != 0) { omemo_start_session(jid); } - free(our_barejid); } #endif } diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index 23c3d375..14c05a38 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -86,8 +86,8 @@ void omemo_devicelist_configure(void) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); - Jid* jid = jid_create(connection_get_fulljid()); + auto_char char* id = connection_create_stanza_id(); + auto_jid Jid* jid = jid_create(connection_get_fulljid()); xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST); @@ -96,15 +96,13 @@ omemo_devicelist_configure(void) iq_send_stanza(iq); xmpp_stanza_release(iq); - free(id); - jid_destroy(jid); } void omemo_devicelist_request(const char* const jid) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); log_debug("[OMEMO] request device list for jid: %s", jid); @@ -113,7 +111,6 @@ omemo_devicelist_request(const char* const jid) iq_send_stanza(iq); - free(id); xmpp_stanza_release(iq); } diff --git a/src/xmpp/ox.c b/src/xmpp/ox.c index 85fef800..0f85224f 100644 --- a/src/xmpp/ox.c +++ b/src/xmpp/ox.c @@ -124,9 +124,8 @@ ox_announce_public_key(const char* const filename) xmpp_stanza_t* item = xmpp_stanza_new(ctx); xmpp_stanza_set_name(item, STANZA_NAME_ITEM); - char* timestamp = _gettimestamp(); + auto_char char* timestamp = _gettimestamp(); xmpp_stanza_set_attribute(item, STANZA_ATTR_ID, timestamp); - free(timestamp); xmpp_stanza_t* pubkey = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubkey, STANZA_NAME_PUPKEY); @@ -267,9 +266,8 @@ _ox_metadata_node__public_key(const char* const fingerprint) xmpp_stanza_t* pubkeymetadata = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubkeymetadata, STANZA_NAME_PUBKEY_METADATA); xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_V4_FINGERPRINT, fingerprint); - char* timestamp = _gettimestamp(); + auto_char char* timestamp = _gettimestamp(); xmpp_stanza_set_attribute(pubkeymetadata, STANZA_ATTR_DATE, timestamp); - free(timestamp); xmpp_stanza_add_child(publickeyslist, pubkeymetadata); xmpp_stanza_add_child(item, publickeyslist); @@ -467,7 +465,7 @@ _ox_public_key_result(xmpp_stanza_t* const stanza, void* const userdata) log_error("[OX] No data"); } - char* base64_data = xmpp_stanza_get_text(data); + auto_char char* base64_data = xmpp_stanza_get_text(data); if (base64_data) { log_debug("Key data: %s", base64_data); @@ -476,8 +474,6 @@ _ox_public_key_result(xmpp_stanza_t* const stanza, void* const userdata) } else { cons_show("Public Key import failed. Check log for details."); } - - free(base64_data); } return FALSE; diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index fd265535..d5dd01ec 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -124,9 +124,8 @@ presence_subscription(const char* const jid, const jabber_subscr_t action) xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_stanza_t* presence = xmpp_presence_new(ctx); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_set_id(presence, id); - free(id); xmpp_stanza_set_type(presence, type); xmpp_stanza_set_to(presence, jidp->barejid); @@ -207,9 +206,8 @@ presence_send(const resource_presence_t presence_type, const int idle, char* sig xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_stanza_t* presence = xmpp_presence_new(ctx); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_set_id(presence, id); - free(id); const char* show = stanza_get_presence_string_from_type(presence_type); stanza_attach_show(ctx, presence, show); @@ -265,10 +263,9 @@ _send_room_presence(xmpp_stanza_t* presence) const char* nick = muc_nick(room); if (nick) { - char* full_room_jid = create_fulljid(room, nick); + auto_char char* full_room_jid = create_fulljid(room, nick); xmpp_stanza_set_to(presence, full_room_jid); log_debug("Sending presence to room: %s", full_room_jid); - free(full_room_jid); _send_presence_stanza(presence); } @@ -313,7 +310,7 @@ presence_change_room_nick(const char* const room, const char* const nick) const char* show = stanza_get_presence_string_from_type(presence_type); char* status = connection_get_presence_msg(); int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type); - char* full_room_jid = create_fulljid(room, nick); + auto_char char* full_room_jid = create_fulljid(room, nick); xmpp_ctx_t* ctx = connection_get_ctx(); xmpp_stanza_t* presence = stanza_create_room_newnick_presence(ctx, full_room_jid); @@ -325,7 +322,6 @@ presence_change_room_nick(const char* const room, const char* const nick) _send_presence_stanza(presence); xmpp_stanza_release(presence); - free(full_room_jid); } void @@ -451,7 +447,7 @@ _presence_error_handler(xmpp_stanza_t* const stanza) } // stanza_get_error never returns NULL - char* err_msg = stanza_get_error_message(stanza); + auto_char char* err_msg = stanza_get_error_message(stanza); g_string_append(log_msg, " error="); g_string_append(log_msg, err_msg); @@ -464,8 +460,6 @@ _presence_error_handler(xmpp_stanza_t* const stanza) } else { ui_handle_error(err_msg); } - - free(err_msg); } static void @@ -544,7 +538,7 @@ _unavailable_handler(xmpp_stanza_t* const stanza) } if (strcmp(my_jid->barejid, from_jid->barejid) != 0) { - char* status_str = stanza_get_status(stanza, NULL); + auto_char char* status_str = stanza_get_status(stanza, NULL); if (from_jid->resourcepart) { sv_ev_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); @@ -552,7 +546,6 @@ _unavailable_handler(xmpp_stanza_t* const stanza) } else { sv_ev_contact_offline(from_jid->barejid, "__prof_default", status_str); } - free(status_str); } else { if (from_jid->resourcepart) { connection_remove_available_resource(from_jid->resourcepart); @@ -575,25 +568,22 @@ _handle_caps(const char* const jid, XMPPCaps* caps) caps_map_jid_to_ver(jid, caps->ver); } else { log_debug("Capabilities cache miss: %s, for %s, sending service discovery request", caps->ver, jid); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); iq_send_caps_request(jid, id, caps->node, caps->ver); - free(id); } } // unsupported hash, xep-0115, associate with JID, no cache } else if (caps->hash) { log_info("Hash %s not supported: %s, sending service discovery request", caps->hash, jid); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); iq_send_caps_request_for_jid(jid, id, caps->node, caps->ver); - free(id); // no hash, legacy caps, cache against node#ver } else if (caps->node && caps->ver) { log_info("No hash specified: %s, legacy request made for %s#%s", jid, caps->node, caps->ver); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); iq_send_caps_request_legacy(jid, id, caps->node, caps->ver); - free(id); } else { log_info("No hash specified: %s, could not create ver string, not sending service discovery request.", jid); } @@ -783,25 +773,21 @@ _muc_user_self_handler(xmpp_stanza_t* stanza) // room destroyed if (stanza_room_destroyed(stanza)) { const char* new_jid = stanza_get_muc_destroy_alternative_room(stanza); - char* password = stanza_get_muc_destroy_alternative_password(stanza); - char* reason = stanza_get_muc_destroy_reason(stanza); + auto_char char* password = stanza_get_muc_destroy_alternative_password(stanza); + auto_char char* reason = stanza_get_muc_destroy_reason(stanza); sv_ev_room_destroyed(room, new_jid, password, reason); - free(password); - free(reason); // kicked from room } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0)) { const char* actor = stanza_get_actor(stanza); - char* reason = stanza_get_reason(stanza); + auto_char char* reason = stanza_get_reason(stanza); sv_ev_room_kicked(room, actor, reason); - free(reason); // banned from room } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0)) { const char* actor = stanza_get_actor(stanza); - char* reason = stanza_get_reason(stanza); + auto_char char* reason = stanza_get_reason(stanza); sv_ev_room_banned(room, actor, reason); - free(reason); // normal exit } else { @@ -818,9 +804,9 @@ _muc_user_self_handler(xmpp_stanza_t* stanza) } muc_nick_change_complete(room, nick); - char* reason = stanza_get_reason(stanza); - char* show_str = stanza_get_show(stanza, "online"); - char* status_str = stanza_get_status(stanza, NULL); + auto_char char* reason = stanza_get_reason(stanza); + auto_char char* show_str = stanza_get_show(stanza, "online"); + auto_char char* status_str = stanza_get_status(stanza, NULL); const char* actor = stanza_get_actor(stanza); const char* jid = NULL; const char* role = NULL; @@ -836,9 +822,6 @@ _muc_user_self_handler(xmpp_stanza_t* stanza) } } sv_ev_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str); - free(show_str); - free(status_str); - free(reason); } jid_destroy(from_jid); @@ -848,13 +831,13 @@ static void _muc_user_occupant_handler(xmpp_stanza_t* stanza) { const char* from = xmpp_stanza_get_from(stanza); - Jid* from_jid = jid_create(from); + auto_jid Jid* from_jid = jid_create(from); log_debug("Room presence received from %s", from_jid->fulljid); char* room = from_jid->barejid; char* nick = from_jid->resourcepart; - char* status_str = stanza_get_status(stanza, NULL); + auto_char char* status_str = stanza_get_status(stanza, NULL); if (!nick) { log_warning("presence: jid without resource"); @@ -876,16 +859,14 @@ _muc_user_occupant_handler(xmpp_stanza_t* stanza) // kicked from room if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0)) { const char* actor = stanza_get_actor(stanza); - char* reason = stanza_get_reason(stanza); + auto_char char* reason = stanza_get_reason(stanza); sv_ev_room_occupent_kicked(room, nick, actor, reason); - free(reason); // banned from room } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0)) { const char* actor = stanza_get_actor(stanza); - char* reason = stanza_get_reason(stanza); + auto_char char* reason = stanza_get_reason(stanza); sv_ev_room_occupent_banned(room, nick, actor, reason); - free(reason); // normal exit } else { @@ -905,8 +886,8 @@ _muc_user_occupant_handler(xmpp_stanza_t* stanza) stanza_free_caps(caps); const char* actor = stanza_get_actor(stanza); - char* show_str = stanza_get_show(stanza, "online"); - char* reason = stanza_get_reason(stanza); + auto_char char* show_str = stanza_get_show(stanza, "online"); + auto_char char* reason = stanza_get_reason(stanza); const char* jid = NULL; const char* role = NULL; const char* affiliation = NULL; @@ -920,12 +901,7 @@ _muc_user_occupant_handler(xmpp_stanza_t* stanza) } } sv_ev_muc_occupant_online(room, nick, jid, role, affiliation, actor, reason, show_str, status_str); - free(show_str); - free(reason); } - - jid_destroy(from_jid); - free(status_str); } static void @@ -968,10 +944,9 @@ _send_presence_stanza(xmpp_stanza_t* const stanza) xmpp_stanza_to_text(stanza, &text, &text_size); xmpp_conn_t* conn = connection_get_conn(); - char* plugin_text = plugins_on_presence_stanza_send(text); + auto_char char* plugin_text = plugins_on_presence_stanza_send(text); if (plugin_text) { xmpp_send_raw_string(conn, "%s", plugin_text); - free(plugin_text); } else { xmpp_send_raw_string(conn, "%s", text); } diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index fd7ceecf..71a4c3d7 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -84,9 +84,8 @@ void roster_send_add_new(const char* const barejid, const char* const name) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_roster_set(ctx, id, barejid, name, NULL); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -104,9 +103,8 @@ void roster_send_name_change(const char* const barejid, const char* const new_name, GSList* groups) { xmpp_ctx_t* const ctx = connection_get_ctx(); - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_roster_set(ctx, id, barejid, new_name, groups); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -123,7 +121,7 @@ roster_send_add_to_group(const char* const group, PContact contact) new_groups = g_slist_append(new_groups, strdup(group)); // add an id handler to handle the response - char* unique_id = connection_create_stanza_id(); + auto_char char* unique_id = connection_create_stanza_id(); GroupData* data = malloc(sizeof(GroupData)); data->group = strdup(group); if (p_contact_name(contact)) { @@ -138,7 +136,6 @@ roster_send_add_to_group(const char* const group, PContact contact) p_contact_name(contact), new_groups); iq_send_stanza(iq); xmpp_stanza_release(iq); - free(unique_id); } static int @@ -166,7 +163,7 @@ roster_send_remove_from_group(const char* const group, PContact contact) xmpp_ctx_t* const ctx = connection_get_ctx(); // add an id handler to handle the response - char* unique_id = connection_create_stanza_id(); + auto_char char* unique_id = connection_create_stanza_id(); GroupData* data = malloc(sizeof(GroupData)); data->group = strdup(group); if (p_contact_name(contact)) { @@ -180,7 +177,6 @@ roster_send_remove_from_group(const char* const group, PContact contact) p_contact_name(contact), new_groups); iq_send_stanza(iq); xmpp_stanza_release(iq); - free(unique_id); } static int @@ -204,17 +200,15 @@ roster_set_handler(xmpp_stanza_t* const stanza) } // if from attribute exists and it is not current users barejid, ignore push - char* mybarejid = connection_get_barejid(); + auto_char char* mybarejid = connection_get_barejid(); const char* from = xmpp_stanza_get_from(stanza); if (from && (strcmp(from, mybarejid) != 0)) { log_warning("Received alleged roster push from: %s", from); - free(mybarejid); return; } - free(mybarejid); const char* barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); - gchar* barejid_lower = g_utf8_strdown(barejid, -1); + auto_gchar gchar* barejid_lower = g_utf8_strdown(barejid, -1); const char* name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char* sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); const char* ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); @@ -256,8 +250,6 @@ roster_set_handler(xmpp_stanza_t* const stanza) } } - g_free(barejid_lower); - return; } diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c index 90f982e6..69c59a33 100644 --- a/src/xmpp/roster_list.c +++ b/src/xmpp/roster_list.c @@ -264,7 +264,7 @@ roster_change_name(PContact contact, const char* const new_name) assert(roster != NULL); assert(contact != NULL); - char* current_name = NULL; + auto_char char* current_name = NULL; const char* barejid = p_contact_barejid(contact); if (p_contact_name(contact)) { @@ -273,7 +273,6 @@ roster_change_name(PContact contact, const char* const new_name) p_contact_set_name(contact, new_name); _replace_name(current_name, new_name, barejid); - free(current_name); } void @@ -415,6 +414,15 @@ roster_add(const char* const barejid, const char* const name, GSList* groups, co return TRUE; } +/** + * Retrieve the bare JID from the roster based on the name. + * + * @param name The name associated with the bare JID. + * @return The corresponding bare JID if found, or NULL if not found. + * + * @note The returned value should not be freed explicitly. The memory + * management is handled by the underlying hash table. + */ char* roster_barejid_from_name(const char* const name) { diff --git a/src/xmpp/session.c b/src/xmpp/session.c index 390441a4..5ae8030b 100644 --- a/src/xmpp/session.c +++ b/src/xmpp/session.c @@ -121,7 +121,7 @@ session_connect_with_account(const ProfAccount* const account) saved_account.name = strdup(account->name); saved_account.passwd = strdup(account->password); - char* jid = NULL; + auto_char char* jid = NULL; if (account->resource) { Jid* jidp = jid_create_from_bare_and_resource(account->jid, account->resource); jid = strdup(jidp->fulljid); @@ -137,7 +137,6 @@ session_connect_with_account(const ProfAccount* const account) account->port, account->tls_policy, account->auth_policy); - free(jid); return result; } @@ -179,9 +178,8 @@ session_connect_with_details(const char* const jid, const char* const passwd, co Jid* jidp = jid_create(jid); if (jidp->resourcepart == NULL) { jid_destroy(jidp); - char* resource = jid_random_resource(); + auto_char char* resource = jid_random_resource(); jidp = jid_create_from_bare_and_resource(jid, resource); - free(resource); saved_details.jid = strdup(jidp->fulljid); } else { saved_details.jid = strdup(jid); @@ -560,7 +558,7 @@ session_reconnect_now(void) return; } - char* jid = NULL; + auto_char char* jid = NULL; if (account->resource) { jid = create_fulljid(account->jid, account->resource); } else { @@ -578,7 +576,6 @@ session_reconnect_now(void) log_debug("Attempting reconnect with account %s", account->name); connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy); - free(jid); account_free(account); if (reconnect_timer) g_timer_start(reconnect_timer); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index bbc15c13..3ff47577 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -128,9 +128,8 @@ xmpp_stanza_t* stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char *const jid, const gboolean autojoin, const char *const nick) { - char *id = connection_create_stanza_id(); + auto_char char *id = connection_create_stanza_id(); xmpp_stanza_t *stanza = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB); @@ -225,7 +224,7 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id, xmpp_stanza_set_name(request, STANZA_NAME_REQUEST); xmpp_stanza_set_ns(request, STANZA_NS_HTTP_UPLOAD); - char* filename_cpy = strdup(upload->filename); + auto_char char* filename_cpy = strdup(upload->filename); // strip spaces from filename (servers don't spaces) for (int i = 0; i < strlen(filename_cpy); i++) { if (filename_cpy[i] == ' ') { @@ -233,7 +232,6 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id, } } xmpp_stanza_set_attribute(request, STANZA_ATTR_FILENAME, basename(filename_cpy)); - free(filename_cpy); gchar* filesize = g_strdup_printf("%jd", (intmax_t)(upload->filesize)); if (filesize) { @@ -252,9 +250,8 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id, xmpp_stanza_t* stanza_enable_carbons(xmpp_ctx_t* ctx) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* carbons_enable = xmpp_stanza_new(ctx); xmpp_stanza_set_name(carbons_enable, STANZA_NAME_ENABLE); @@ -269,9 +266,8 @@ stanza_enable_carbons(xmpp_ctx_t* ctx) xmpp_stanza_t* stanza_disable_carbons(xmpp_ctx_t* ctx) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* carbons_disable = xmpp_stanza_new(ctx); xmpp_stanza_set_name(carbons_disable, STANZA_NAME_DISABLE); @@ -286,9 +282,8 @@ stanza_disable_carbons(xmpp_ctx_t* ctx) xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t* ctx, const char* const fulljid, const char* const state) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* msg = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id); - free(id); xmpp_stanza_t* chat_state = xmpp_stanza_new(ctx); xmpp_stanza_set_name(chat_state, state); @@ -418,9 +413,8 @@ stanza_attach_x_oob_url(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza, const char* cons xmpp_stanza_t* stanza_create_roster_remove_set(xmpp_ctx_t* ctx, const char* const barejid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -483,9 +477,8 @@ xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t* ctx, const char* const room, const char* const contact, const char* const reason, const char* const password) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, NULL, contact, id); - free(id); xmpp_stanza_t* x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); @@ -509,9 +502,8 @@ xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t* ctx, const char* const room, const char* const contact, const char* const reason) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, NULL, room, id); - free(id); xmpp_stanza_t* x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); @@ -601,9 +593,8 @@ stanza_create_room_leave_presence(xmpp_ctx_t* ctx, const char* const room, xmpp_stanza_t* stanza_create_instant_room_request_iq(xmpp_ctx_t* ctx, const char* const room_jid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room_jid); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -627,9 +618,8 @@ stanza_create_instant_room_request_iq(xmpp_ctx_t* ctx, const char* const room_ji xmpp_stanza_t* stanza_create_instant_room_destroy_iq(xmpp_ctx_t* ctx, const char* const room_jid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room_jid); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -651,9 +641,8 @@ stanza_create_instant_room_destroy_iq(xmpp_ctx_t* ctx, const char* const room_ji xmpp_stanza_t* stanza_create_room_config_request_iq(xmpp_ctx_t* ctx, const char* const room_jid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); - free(id); xmpp_stanza_set_to(iq, room_jid); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -669,9 +658,8 @@ stanza_create_room_config_request_iq(xmpp_ctx_t* ctx, const char* const room_jid xmpp_stanza_t* stanza_create_room_config_cancel_iq(xmpp_ctx_t* ctx, const char* const room_jid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room_jid); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -695,9 +683,8 @@ stanza_create_room_config_cancel_iq(xmpp_ctx_t* ctx, const char* const room_jid) xmpp_stanza_t* stanza_create_room_affiliation_list_iq(xmpp_ctx_t* ctx, const char* const room, const char* const affiliation) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -719,9 +706,8 @@ stanza_create_room_affiliation_list_iq(xmpp_ctx_t* ctx, const char* const room, xmpp_stanza_t* stanza_create_room_role_list_iq(xmpp_ctx_t* ctx, const char* const room, const char* const role) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -744,9 +730,8 @@ xmpp_stanza_t* stanza_create_room_affiliation_set_iq(xmpp_ctx_t* ctx, const char* const room, const char* const jid, const char* const affiliation, const char* const reason) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -782,9 +767,8 @@ xmpp_stanza_t* stanza_create_room_role_set_iq(xmpp_ctx_t* const ctx, const char* const room, const char* const nick, const char* const role, const char* const reason) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -820,9 +804,8 @@ xmpp_stanza_t* stanza_create_room_kick_iq(xmpp_ctx_t* const ctx, const char* const room, const char* const nick, const char* const reason) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -857,9 +840,8 @@ stanza_create_room_kick_iq(xmpp_ctx_t* const ctx, const char* const room, const xmpp_stanza_t* stanza_create_software_version_iq(xmpp_ctx_t* ctx, const char* const fulljid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); - free(id); xmpp_stanza_set_to(iq, fulljid); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -946,9 +928,8 @@ stanza_create_last_activity_iq(xmpp_ctx_t* ctx, const char* const id, const char xmpp_stanza_t* stanza_create_room_config_submit_iq(xmpp_ctx_t* ctx, const char* const room, DataForm* form) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -1028,9 +1009,8 @@ stanza_contains_chat_state(xmpp_stanza_t* stanza) xmpp_stanza_t* stanza_create_ping_iq(xmpp_ctx_t* ctx, const char* const target) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); - free(id); if (target) { xmpp_stanza_set_to(iq, target); } @@ -1739,10 +1719,10 @@ stanza_parse_caps(xmpp_stanza_t* const stanza) EntityCapabilities* stanza_create_caps_from_query_element(xmpp_stanza_t* query) { - char* software = NULL; - char* software_version = NULL; - char* os = NULL; - char* os_version = NULL; + auto_char char* software = NULL; + auto_char char* software_version = NULL; + auto_char char* os = NULL; + auto_char char* os_version = NULL; xmpp_stanza_t* softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); if (softwareinfo) { @@ -1851,10 +1831,6 @@ stanza_create_caps_from_query_element(xmpp_stanza_t* query) EntityCapabilities* result = caps_create(category, type, name, software, software_version, os, os_version, features); g_slist_free_full(features, free); - free(software); - free(software_version); - free(os); - free(os_version); return result; } @@ -2209,9 +2185,8 @@ xmpp_stanza_t* stanza_create_command_exec_iq(xmpp_ctx_t* ctx, const char* const target, const char* const node) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, target); xmpp_stanza_t* command = xmpp_stanza_new(ctx); @@ -2231,9 +2206,8 @@ xmpp_stanza_t* stanza_create_command_config_submit_iq(xmpp_ctx_t* ctx, const char* const room, const char* const node, const char* const sessionid, DataForm* form) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_to(iq, room); xmpp_stanza_t* command = xmpp_stanza_new(ctx); @@ -2281,9 +2255,8 @@ stanza_create_omemo_devicelist_request(xmpp_ctx_t* ctx, const char* const id, xmpp_stanza_t* stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t* ctx, const char* const jid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB); @@ -2306,9 +2279,8 @@ stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t* ctx, const char* const jid) xmpp_stanza_t* stanza_create_omemo_devicelist_publish(xmpp_ctx_t* ctx, GList* const ids) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB); @@ -2541,9 +2513,8 @@ stanza_attach_origin_id(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza, const char* cons static void _stanza_add_unique_id(xmpp_stanza_t* stanza) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_set_id(stanza, id); - free(id); } static char* @@ -2594,9 +2565,8 @@ stanza_create_avatar_retrieve_data_request(xmpp_ctx_t* ctx, const char* stanza_i xmpp_stanza_t* stanza_create_avatar_data_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsize len) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_attribute(iq, STANZA_ATTR_FROM, connection_get_fulljid()); xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); @@ -2618,9 +2588,8 @@ stanza_create_avatar_data_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsiz xmpp_stanza_set_ns(data, STANZA_NS_USER_AVATAR_DATA); xmpp_stanza_t* text = xmpp_stanza_new(ctx); - gchar* base64 = g_base64_encode((guchar*)img_data, len); + auto_gchar gchar* base64 = g_base64_encode((guchar*)img_data, len); xmpp_stanza_set_text(text, base64); - free(base64); xmpp_stanza_add_child(data, text); xmpp_stanza_add_child(item, data); @@ -2640,9 +2609,8 @@ stanza_create_avatar_data_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsiz xmpp_stanza_t* stanza_create_avatar_metadata_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsize len, int height, int width) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_attribute(iq, STANZA_ATTR_FROM, connection_get_fulljid()); xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); @@ -2692,9 +2660,8 @@ stanza_create_avatar_metadata_publish_iq(xmpp_ctx_t* ctx, const char* img_data, xmpp_stanza_t* stanza_disable_avatar_publish_iq(xmpp_ctx_t* ctx) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_set_attribute(iq, STANZA_ATTR_FROM, connection_get_fulljid()); xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx); @@ -2773,9 +2740,8 @@ _text_stanza(xmpp_ctx_t* ctx, const char* name, const char* text) xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char* const enddate, const char* const firstid, const char* const lastid) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); // xmpp_stanza_set_to(iq, jid); xmpp_stanza_t* query = xmpp_stanza_new(ctx); @@ -2861,9 +2827,8 @@ stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const s xmpp_stanza_t* stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* const password) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* change_password = xmpp_stanza_new(ctx); xmpp_stanza_set_name(change_password, STANZA_NAME_QUERY); @@ -2898,9 +2863,8 @@ stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* cons xmpp_stanza_t* stanza_register_new_account(xmpp_ctx_t* ctx, const char* const user, const char* const password) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); - free(id); xmpp_stanza_t* register_new_account = xmpp_stanza_new(ctx); xmpp_stanza_set_name(register_new_account, STANZA_NAME_QUERY); @@ -2935,9 +2899,8 @@ stanza_register_new_account(xmpp_ctx_t* ctx, const char* const user, const char* xmpp_stanza_t* stanza_request_voice(xmpp_ctx_t* ctx, const char* const room) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, NULL, room, id); - free(id); xmpp_stanza_t* request_voice_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(request_voice_st, STANZA_NAME_X); @@ -2993,9 +2956,8 @@ stanza_request_voice(xmpp_ctx_t* ctx, const char* const room) xmpp_stanza_t* stanza_create_approve_voice(xmpp_ctx_t* ctx, const char* const id, const char* const jid, const char* const node, DataForm* form) { - char* stid = connection_create_stanza_id(); + auto_char char* stid = connection_create_stanza_id(); xmpp_stanza_t* message = xmpp_message_new(ctx, NULL, jid, stid); - free(stid); xmpp_stanza_t* x = form_create_submission(form); diff --git a/src/xmpp/vcard.c b/src/xmpp/vcard.c index b3ff5d39..69e68cce 100644 --- a/src/xmpp/vcard.c +++ b/src/xmpp/vcard.c @@ -1242,12 +1242,11 @@ vcard_print(xmpp_ctx_t* ctx, ProfWin* window, char* jid) data->window = window; - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_vcard_request_iq(ctx, jid, id); iq_id_handler_add(id, _vcard_print_result, (ProfIqFreeCallback)_free_userdata, data); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -1306,9 +1305,8 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata) GString* filename; if (!data->filename) { - char* path = files_get_data_path(DIR_PHOTOS); + auto_gchar gchar* path = files_get_data_path(DIR_PHOTOS); filename = g_string_new(path); - free(path); g_string_append(filename, "/"); errno = 0; @@ -1405,12 +1403,11 @@ vcard_photo(xmpp_ctx_t* ctx, char* jid, char* filename, int index, gboolean open data->filename = strdup(filename); } - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_vcard_request_iq(ctx, jid, id); iq_id_handler_add(id, _vcard_photo_result, (ProfIqFreeCallback)_free_userdata, data); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -1441,12 +1438,11 @@ vcard_user_refresh(void) return; } - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = stanza_create_vcard_request_iq(connection_get_ctx(), NULL, id); iq_id_handler_add(id, _vcard_refresh_result, NULL, NULL); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); } @@ -1455,7 +1451,7 @@ vcard_user_refresh(void) void vcard_upload(xmpp_ctx_t* ctx, vCard* vcard) { - char* id = connection_create_stanza_id(); + auto_char char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); xmpp_stanza_set_from(iq, connection_get_fulljid()); @@ -1463,14 +1459,12 @@ vcard_upload(xmpp_ctx_t* ctx, vCard* vcard) if (!vcard_stanza) { xmpp_stanza_release(iq); - free(id); return; } xmpp_stanza_add_child(iq, vcard_stanza); xmpp_stanza_release(vcard_stanza); - free(id); iq_send_stanza(iq); xmpp_stanza_release(iq); } diff --git a/tests/unittests/test_cmd_alias.c b/tests/unittests/test_cmd_alias.c index 718bca2a..6d01ee14 100644 --- a/tests/unittests/test_cmd_alias.c +++ b/tests/unittests/test_cmd_alias.c @@ -73,7 +73,7 @@ cmd_alias_add_adds_alias(void** state) gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - char* returned_val = prefs_get_alias("hc"); + gchar* returned_val = prefs_get_alias("hc"); assert_string_equal("/help commands", returned_val); free(returned_val); @@ -106,7 +106,7 @@ cmd_alias_remove_removes_alias(void** state) gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - char* returned_val = prefs_get_alias("hn"); + gchar* returned_val = prefs_get_alias("hn"); assert_null(returned_val); free(returned_val);