1
0
Fork 0

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

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

@ -35,6 +35,7 @@
*/
#include "config.h"
#include "common.h"
#include <stdlib.h>
#include <string.h>
@ -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);

View File

@ -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;
@ -159,24 +158,18 @@ files_get_config_path(const char* const config_base)
gchar*
files_get_data_path(const char* const data_base)
{
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, date_base);
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*

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -91,72 +91,60 @@ c_api_register_command(const char* filename, const char* command_name, int min_a
char** synopsis, const char* description, char* arguments[][2], char** examples,
void (*callback)(char** args))
{
char* plugin_name = _c_plugin_name(filename);
auto_char char* plugin_name = _c_plugin_name(filename)