Change char->free to auto_char char for autocleanup

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

Related to #1819.

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

View File

@@ -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);
}
}

View File

@@ -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