1
0
Fork 0

`g_free()` to `auto_gfree`, introduce `auto_guchar`

Fix 11 potential mem leaks in theme.c
This commit is contained in:
John Hernandez 2023-07-13 17:04:59 +02:00
parent 3a4cd7da48
commit 8304ac86ff
39 changed files with 145 additions and 233 deletions

View File

@ -4387,9 +4387,8 @@ _url_autocomplete(ProfWin* window, const char* const input, gboolean previous)
if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) {
result = autocomplete_param_with_func(input, "/url save", wins_get_url, previous, window);
} else if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
gchar* cmd = g_strdup_printf("/url save %s", args[1]);
auto_gchar gchar* cmd = g_strdup_printf("/url save %s", args[1]);
result = cmd_ac_complete_filepath(input, cmd, previous);
g_free(cmd);
}
}
}

View File

@ -3039,14 +3039,13 @@ command_mangen(void)
create_dir("docs");
GDateTime* now = g_date_time_new_now_local();
gchar* date = g_date_time_format(now, "%F");
gchar* header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
auto_gchar gchar* date = g_date_time_format(now, "%F");
auto_gchar gchar* header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
if (!header) {
log_error("command_mangen(): could not allocate memory");
return;
}
g_date_time_unref(now);
g_free(date);
GList* curr = cmds;
while (curr) {
@ -3098,6 +3097,5 @@ command_mangen(void)
printf("\nProcessed %d commands.\n\n", g_list_length(cmds));
g_free(header);
g_list_free(cmds);
}

View File

@ -3635,7 +3635,7 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* room = NULL;
auto_gchar gchar* room = NULL;
char* nick = NULL;
char* passwd = NULL;
char* account_name = session_get_account_name();
@ -3663,7 +3663,6 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
if (!parsed) {
cons_bad_cmd_usage(command);
cons_show("");
g_free(room);
jid_destroy(room_arg);
return TRUE;
}
@ -3693,7 +3692,6 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
ui_switch_to_room(room);
}
g_free(room);
jid_destroy(room_arg);
account_free(account);
@ -4578,8 +4576,8 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
gchar* service = NULL;
gchar* filter = NULL;
auto_gchar gchar* service = NULL;
auto_gchar gchar* filter = NULL;
if (args[0] != NULL) {
if (g_strcmp0(args[0], "service") == 0) {
if (args[1] == NULL) {
@ -4628,8 +4626,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
if (args[3] == NULL) {
cons_bad_cmd_usage(command);
cons_show("");
g_free(service);
g_free(filter);
return TRUE;
}
g_free(service);
@ -4638,8 +4634,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
if (args[3] == NULL) {
cons_bad_cmd_usage(command);
cons_show("");
g_free(service);
g_free(filter);
return TRUE;
}
g_free(filter);
@ -4647,8 +4641,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
} else {
cons_bad_cmd_usage(command);
cons_show("");
g_free(service);
g_free(filter);
return TRUE;
}
}
@ -4661,8 +4653,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
} else {
cons_show("Account MUC service property not found.");
account_free(account);
g_free(service);
g_free(filter);
return TRUE;
}
}
@ -4675,9 +4665,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
}
iq_room_list_request(service, filter);
g_free(service);
g_free(filter);
return TRUE;
}
@ -9680,11 +9667,9 @@ _cmd_executable_template(const preference_t setting, const char* command, gchar*
}
if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) {
gchar* str = g_strjoinv(" ", &args[2]);
auto_gchar gchar* str = g_strjoinv(" ", &args[2]);
prefs_set_string(setting, str);
cons_show("`%s` command set to invoke '%s'", command, str);
g_free(str);
} else if (g_strcmp0(args[1], "default") == 0) {
prefs_set_string(setting, NULL);
auto_gchar gchar* def = prefs_get_string(setting);
@ -10129,7 +10114,7 @@ cmd_vcard_photo(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* jid = NULL;
auto_gchar gchar* jid = NULL;
char* filepath = NULL;
int index = 0;
@ -10241,9 +10226,6 @@ cmd_vcard_photo(ProfWin* window, const char* const command, gchar** args)
cons_bad_cmd_usage(command);
}
if (!jidless) {
g_free(jid);
}
return TRUE;
}

View File

@ -78,6 +78,15 @@ auto_free_gchar(gchar** str)
g_free(*str);
}
void
auto_free_guchar(guchar** ptr)
{
if (ptr == NULL) {
return;
}
g_free(*ptr);
}
void
auto_free_gcharv(gchar*** args)
{
@ -545,16 +554,14 @@ basename_from_url(const char* url)
const char* default_name = "index";
GFile* file = g_file_new_for_commandline_arg(url);
char* basename = g_file_get_basename(file);
if (_has_directory_suffix(basename)) {
g_free(basename);
basename = strdup(default_name);
}
auto_gchar gchar* basename = g_file_get_basename(file);
g_object_unref(file);
return basename;
if (_has_directory_suffix(basename)) {
return strdup(default_name);
}
return strdup(basename);
}
gchar*
@ -589,9 +596,8 @@ unique_filename_from_url(const char* url, const char* path)
if (_has_directory_suffix(realpath) || g_file_test(realpath, G_FILE_TEST_IS_DIR)) {
// The target should be used as a directory. Assume that the basename
// should be derived from the URL.
char* basename = basename_from_url(url);
auto_char char* basename = basename_from_url(url);
filename = g_build_filename(g_file_peek_path(target), basename, NULL);
g_free(basename);
} else {
// Just use the target as filename.
filename = g_build_filename(g_file_peek_path(target), NULL);

View File

@ -31,6 +31,9 @@
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
* @file common.h
*
* @brief Common utilities for the project.
*/
#ifndef COMMON_H
@ -56,6 +59,25 @@ void auto_free_gcharv(gchar*** args);
#define auto_gcharv __attribute__((__cleanup__(auto_free_gcharv)))
void auto_free_char(char** str);
#define auto_char __attribute__((__cleanup__(auto_free_char)))
/**
* Frees the memory allocated for a guchar* string.
*
* @param str Pointer to the guchar* string to be freed. If NULL, no action is taken.
*/
void auto_free_guchar(guchar** str);
/**
* @brief Macro for automatically freeing a guchar* string when it goes out of scope.
*
* This macro is used to automatically free a guchar* string when it goes out of scope.
* It utilizes the `auto_free_guchar` function and should be placed before the variable declaration.
*
* Example usage:
* ```
* auto_guchar guchar* myString = g_base64_decode("SGVsbG8sIHdvcmxkIQ==", NULL);
* ```
*/
#define auto_guchar __attribute__((__cleanup__(auto_free_guchar)))
#if defined(__OpenBSD__)
#define STR_MAYBE_NULL(p) (p) ?: "(null)"

View File

@ -127,7 +127,7 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
{
// set account name and resource
const char* barejid = account_name;
char* resource = jid_random_resource();
auto_gchar gchar* resource = jid_random_resource();
Jid* jid = jid_create(account_name);
if (jid) {
barejid = jid->barejid;
@ -137,7 +137,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
}
if (g_key_file_has_group(accounts, account_name)) {
g_free(resource);
jid_destroy(jid);
return;
}
@ -181,7 +180,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
autocomplete_add(enabled_ac, account_name);
jid_destroy(jid);
g_free(resource);
}
int
@ -433,10 +431,9 @@ accounts_rename(const char* const account_name, const char* const new_name)
};
for (int i = 0; i < ARRAY_SIZE(string_keys); i++) {
char* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
auto_gchar gchar* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
if (value) {
g_key_file_set_string(accounts, new_name, string_keys[i], value);
g_free(value);
}
}
@ -868,7 +865,7 @@ accounts_set_last_activity(const char* const account_name)
}
}
char*
gchar*
accounts_get_last_activity(const char* const account_name)
{
if (accounts_account_exists(account_name)) {
@ -878,7 +875,7 @@ accounts_get_last_activity(const char* const account_name)
}
}
char*
gchar*
accounts_get_resource(const char* const account_name)
{
if (!accounts_account_exists(account_name)) {
@ -909,7 +906,7 @@ resource_presence_t
accounts_get_last_presence(const char* const account_name)
{
resource_presence_t result;
gchar* setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) {
result = RESOURCE_ONLINE;
@ -927,7 +924,6 @@ accounts_get_last_presence(const char* const account_name)
result = RESOURCE_ONLINE;
}
g_free(setting);
return result;
}

View File

@ -61,7 +61,7 @@ void accounts_set_jid(const char* const account_name, const char* const value);
void accounts_set_server(const char* const account_name, const char* const value);
void accounts_set_port(const char* const account_name, const int value);
void accounts_set_resource(const char* const account_name, const char* const value);
char* accounts_get_resource(const char* const account_name);
gchar* accounts_get_resource(const char* const account_name);
void accounts_set_password(const char* const account_name, const char* const value);
void accounts_set_eval_password(const char* const account_name, const char* const value);
void accounts_set_muc_service(const char* const account_name, const char* const value);
@ -72,7 +72,7 @@ void accounts_set_auth_policy(const char* const account_name, const char* const
void accounts_set_last_presence(const char* const account_name, const char* const value);
void accounts_set_last_status(const char* const account_name, const char* const value);
void accounts_set_last_activity(const char* const account_name);
char* accounts_get_last_activity(const char* const account_name);
gchar* accounts_get_last_activity(const char* const account_name);
void accounts_set_login_presence(const char* const account_name, const char* const value);
resource_presence_t accounts_get_login_presence(const char* const account_name);
char* accounts_get_last_status(const char* const account_name);

View File

@ -64,30 +64,27 @@ cafile_add(const TLSCertificate* cert)
log_error("[CAfile] can't store cert with fingerprint %s: PEM is empty", cert->fingerprint);
return;
}
gchar* cafile = _cafile_name();
auto_gchar gchar* cafile = _cafile_name();
if (!cafile)
return;
gchar *contents = NULL, *new_contents = NULL;
auto_gchar gchar* contents = NULL;
auto_gchar gchar* new_contents = NULL;
gsize length;
GError* glib_error = NULL;
if (g_file_test(cafile, G_FILE_TEST_EXISTS)) {
if (!g_file_get_contents(cafile, &contents, &length, &glib_error)) {
log_error("[CAfile] could not read from %s: %s", cafile, glib_error ? glib_error->message : "No GLib error given");
goto out;
return;
}
if (strstr(contents, cert->fingerprint)) {
log_debug("[CAfile] fingerprint %s already stored", cert->fingerprint);
goto out;
return;
}
}
const char* header = "# Profanity CAfile\n# DO NOT EDIT - this file is automatically generated";
new_contents = g_strdup_printf("%s\n\n# %s\n%s", contents ? contents : header, cert->fingerprint, cert->pem);
if (!g_file_set_contents(cafile, new_contents, -1, &glib_error))
log_error("[CAfile] could not write to %s: %s", cafile, glib_error ? glib_error->message : "No GLib error given");
out:
g_free(new_contents);
g_free(contents);
g_free(cafile);
}
gchar*

View File

@ -53,8 +53,8 @@ static char* _files_get_xdg_data_home(void);
void
files_create_directories(void)
{
gchar* xdg_config = _files_get_xdg_config_home();
gchar* xdg_data = _files_get_xdg_data_home();
auto_gchar gchar* xdg_config = _files_get_xdg_config_home();
auto_gchar gchar* xdg_data = _files_get_xdg_data_home();
GString* themes_dir = g_string_new(xdg_config);
g_string_append(themes_dir, "/profanity/themes");
@ -88,17 +88,13 @@ files_create_directories(void)
g_string_free(chatlogs_dir, TRUE);
g_string_free(logs_dir, TRUE);
g_string_free(plugins_dir, TRUE);
g_free(xdg_config);
g_free(xdg_data);
}
gchar*
files_get_inputrc_file(void)
{
gchar* xdg_config = _files_get_xdg_config_home();
auto_gchar gchar* xdg_config = _files_get_xdg_config_home();
GString* inputrc_file = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(inputrc_file, "/profanity/inputrc");
@ -121,11 +117,10 @@ files_get_log_file(const char* const log_file)
GString* logfile;
if (log_file) {
gchar* log_path = g_path_get_dirname(log_file);
auto_gchar gchar* log_path = g_path_get_dirname(log_file);
if (!create_dir(log_path)) {
log_error("Error while creating directory %s", log_path);
}
g_free(log_path);
logfile = g_string_new(log_file);
} else {
@ -149,9 +144,8 @@ files_get_log_file(const char* const log_file)
gchar*
files_get_config_path(const char* const config_base)
{
gchar* xdg_config = _files_get_xdg_config_home();
auto_gchar gchar* xdg_config = _files_get_xdg_config_home();
gchar* result = g_strdup_printf("%s/profanity/%s", xdg_config, config_base);
g_free(xdg_config);
return result;
}

View File

@ -237,10 +237,9 @@ GSList*
theme_list(void)
{
GSList* result = NULL;
gchar* themes_dir = files_get_config_path(DIR_THEMES);
auto_gchar gchar* themes_dir = files_get_config_path(DIR_THEMES);
_theme_list_dir(themes_dir, &result);
g_free(themes_dir);
#ifdef THEMES_PATH
_theme_list_dir(THEMES_PATH, &result);
@ -281,9 +280,8 @@ static void
_set_string_preference(char* prefstr, preference_t pref)
{
if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
gchar* val = g_key_file_get_string(theme, "ui", prefstr, NULL);
auto_gchar gchar* val = g_key_file_get_string(theme, "ui", prefstr, NULL);
prefs_set_string(pref, val);
g_free(val);
}
}
@ -408,100 +406,88 @@ _load_preferences(void)
// load chars from theme and set them to prefs
// with custom set functions
if (g_key_file_has_key(theme, "ui", "occupants.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_occupants_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "occupants.header.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_occupants_header_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_header_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "roster.contact.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_contact_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "roster.resource.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_resource_char(ch);
g_free(ch);
}
} else {
prefs_clear_roster_resource_char();
}
if (g_key_file_has_key(theme, "ui", "roster.rooms.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_room_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "roster.rooms.private.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_room_private_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "roster.private.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_roster_private_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "otr.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_otr_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "pgp.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_pgp_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "omemo.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
if (ch && g_utf8_strlen(ch, 4) == 1) {
prefs_set_omemo_char(ch);
g_free(ch);
}
}
if (g_key_file_has_key(theme, "ui", "correction.char", NULL)) {
gchar* ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
if (ch && strlen(ch) > 0) {
prefs_set_correction_char(ch[0]);
g_free(ch);
}
}
@ -538,11 +524,10 @@ static GString*
_theme_find(const char* const theme_name)
{
GString* path = NULL;
gchar* themes_dir = files_get_config_path(DIR_THEMES);
auto_gchar gchar* themes_dir = files_get_config_path(DIR_THEMES);
if (themes_dir) {
path = g_string_new(themes_dir);
g_free(themes_dir);
g_string_append(path, "/");
g_string_append(path, theme_name);
if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {
@ -641,7 +626,7 @@ theme_main_presence_attrs(const char* const presence)
static void
_theme_prep_bgnd(char* setting, char* def, GString* lookup_str)
{
gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
auto_gchar gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
if (!val) {
g_string_append(lookup_str, def);
} else {
@ -651,7 +636,6 @@ _theme_prep_bgnd(char* setting, char* def, GString* lookup_str)
g_string_append(lookup_str, val);
}
}
g_free(val);
}
/* return value needs to be freed */
@ -666,7 +650,7 @@ theme_get_bkgnd(void)
static void
_theme_prep_fgnd(char* setting, GString* lookup_str, gboolean* bold)
{
gchar* conf_str = g_key_file_get_string(theme, "colours", setting, NULL);
auto_gchar gchar* conf_str = g_key_file_get_string(theme, "colours", setting, NULL);
gchar* val = conf_str;
if (!val)
@ -679,8 +663,6 @@ _theme_prep_fgnd(char* setting, GString* lookup_str, gboolean* bold)
g_string_append(lookup_str, val);
*bold = FALSE;
}
g_free(conf_str);
}
char*

View File

@ -387,8 +387,7 @@ static void
_save_tlscerts(void)
{
gsize g_data_size;
gchar* g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL);
auto_gchar gchar* g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL);
g_file_set_contents(tlscerts_loc, g_tlscerts_data, g_data_size, NULL);
g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR);
g_free(g_tlscerts_data);
}

View File

@ -260,11 +260,10 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const char* s
gchar* sort1 = from_start ? "ASC" : "DESC";
gchar* sort2 = !flip ? "ASC" : "DESC";
GDateTime* now = g_date_time_new_now_local();
gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(now);
auto_gchar gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(now);
auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM (SELECT COALESCE(B.`message`, A.`message`) AS message, A.`timestamp`, A.`from_jid`, A.`type`, A.`encryption` from `ChatLogs` AS A LEFT JOIN `ChatLogs` AS B ON A.`stanza_id` = B.`replace_id` WHERE A.`replace_id` = '' AND ((A.`from_jid` = '%q' AND A.`to_jid` = '%q') OR (A.`from_jid` = '%q' AND A.`to_jid` = '%q')) AND A.`timestamp` < '%q' AND (%Q IS NULL OR A.`timestamp` > %Q) ORDER BY A.`timestamp` %s LIMIT %d) ORDER BY `timestamp` %s;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid, end_date_fmt, start_time, start_time, sort1, MESSAGES_TO_RETRIEVE, sort2);
g_date_time_unref(now);
g_free(end_date_fmt);
if (!query) {
log_error("log_database_get_previous_chat(): SQL query. could not allocate memory");
@ -389,7 +388,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
char* err_msg;
gchar* query;
gchar* date_fmt;
auto_gchar gchar* date_fmt;
if (message->timestamp) {
date_fmt = g_date_time_format_iso8601(message->timestamp);
@ -423,7 +422,6 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
log_error("log_database_add(): SQL query. could not allocate memory");
return;
}
g_free(date_fmt);
if (SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
if (err_msg) {

View File

@ -169,8 +169,8 @@ sv_ev_roster_received(void)
// send initial presence
resource_presence_t conn_presence = accounts_get_login_presence(account_name);
char* last_activity_str = accounts_get_last_activity(account_name);
char* status_message = accounts_get_login_status(account_name);
auto_gchar gchar* last_activity_str = accounts_get_last_activity(account_name);
auto_gchar gchar* status_message = accounts_get_login_status(account_name);
int diff_secs = 0;
if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) {
@ -190,9 +190,6 @@ sv_ev_roster_received(void)
connection_set_presence_msg(status_message);
cl_ev_presence_send(conn_presence, diff_secs);
g_free(status_message);
g_free(last_activity_str);
const char* fulljid = connection_get_fulljid();
plugins_on_connect(account_name, fulljid);
}
@ -278,7 +275,7 @@ sv_ev_room_history(ProfMessage* message)
// check if this message was sent while we were offline.
// if so, treat it as a new message rather than a history event.
char* account_name = session_get_account_name();
char* last_activity = accounts_get_last_activity(account_name);
auto_gchar gchar* last_activity = accounts_get_last_activity(account_name);
int msg_is_new = 0;
if (last_activity) {
@ -292,7 +289,6 @@ sv_ev_room_history(ProfMessage* message)
msg_is_new = (time_diff > 0);
g_date_time_unref(lastdt);
}
g_free(last_activity);
if (msg_is_new) {
sv_ev_room_message(message);

View File

@ -214,13 +214,12 @@ log_msg(log_level_t level, const char* const area, const char* const msg)
char* level_str = _log_abbreviation_string_from_level(level);
gchar* date_fmt = g_date_time_format_iso8601(dt);
auto_gchar gchar* date_fmt = g_date_time_format_iso8601(dt);
fprintf(logp, "%s: %s: %s: %s\n", date_fmt, area, level_str, msg);
g_date_time_unref(dt);
fflush(logp);
g_free(date_fmt);
if (prefs_get_boolean(PREF_LOG_ROTATE) && !user_provided_log) {
long result = ftell(logp);

View File

@ -230,7 +230,7 @@ omemo_on_connect(ProfAccount* account)
omemo_ctx.device_list_handler = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
omemo_ctx.known_devices = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)glib_hash_table_free);
gchar* omemo_dir = files_file_in_account_data_path(DIR_OMEMO, account->jid, NULL);
auto_gchar gchar* omemo_dir = files_file_in_account_data_path(DIR_OMEMO, account->jid, NULL);
if (!omemo_dir) {
log_error("[OMEMO] failed creating directory");
return;
@ -245,8 +245,6 @@ omemo_on_connect(ProfAccount* account)
omemo_ctx.known_devices_filename = g_string_new(omemo_dir);
g_string_append(omemo_ctx.known_devices_filename, "/known_devices.txt");
g_free(omemo_dir);
omemo_devicelist_subscribe();
omemo_ctx.identity_keyfile = g_key_file_new();
@ -1535,7 +1533,7 @@ _load_identity(void)
}
size_t identity_key_public_len;
unsigned char* identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len);
auto_guchar guchar* identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len);
omemo_ctx.identity_key_store.public = signal_buffer_create(identity_key_public, identity_key_public_len);
error = NULL;
@ -1546,7 +1544,7 @@ _load_identity(void)
}
size_t identity_key_private_len;
unsigned char* identity_key_private = g_base64_decode(identity_key_private_b64, &identity_key_private_len);
auto_guchar guchar* identity_key_private = g_base64_decode(identity_key_private_b64, &identity_key_private_len);
omemo_ctx.identity_key_store.private = signal_buffer_create(identity_key_private, identity_key_private_len);
ec_public_key* public_key;
@ -1555,9 +1553,6 @@ _load_identity(void)
curve_decode_private_point(&private_key, identity_key_private, identity_key_private_len, omemo_ctx.signal);
ratchet_identity_key_pair_create(&omemo_ctx.identity_key_pair, public_key, private_key);
g_free(identity_key_public);
g_free(identity_key_private);
char** keys = NULL;
int i;
/* Pre keys */
@ -1567,9 +1562,8 @@ _load_identity(void)
for (i = 0; keys[i] != NULL; i++) {
auto_gchar gchar* pre_key_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_PREKEYS, keys[i], NULL);
size_t pre_key_len;
unsigned char* pre_key = g_base64_decode(pre_key_b64, &pre_key_len);
auto_guchar guchar* pre_key = g_base64_decode(pre_key_b64, &pre_key_len);
signal_buffer* buffer = signal_buffer_create(pre_key, pre_key_len);
g_free(pre_key);
g_hash_table_insert(omemo_ctx.pre_key_store, GINT_TO_POINTER(strtoul(keys[i], NULL, 10)), buffer);
}
@ -1588,9 +1582,8 @@ _load_identity(void)
for (i = 0; keys[i] != NULL; i++) {
auto_gchar gchar* signed_pre_key_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_SIGNED_PREKEYS, keys[i], NULL);
size_t signed_pre_key_len;
unsigned char* signed_pre_key = g_base64_decode(signed_pre_key_b64, &signed_pre_key_len);
auto_guchar guchar* signed_pre_key = g_base64_decode(signed_pre_key_b64, &signed_pre_key_len);
signal_buffer* buffer = signal_buffer_create(signed_pre_key, signed_pre_key_len);
g_free(signed_pre_key);
g_hash_table_insert(omemo_ctx.signed_pre_key_store, GINT_TO_POINTER(strtoul(keys[i], NULL, 10)), buffer);
omemo_ctx.signed_pre_key_id = strtoul(keys[i], NULL, 10);
}
@ -1630,9 +1623,8 @@ _load_trust(void)
for (j = 0; keys[j] != NULL; j++) {
auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL);
size_t key_len;
unsigned char* key = g_base64_decode(key_b64, &key_len);
auto_guchar guchar* key = g_base64_decode(key_b64, &key_len);
signal_buffer* buffer = signal_buffer_create(key, key_len);
g_free(key);
uint32_t device_id = strtoul(keys[j], NULL, 10);
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
}
@ -1663,9 +1655,8 @@ _load_sessions(void)
uint32_t id = strtoul(keys[j], NULL, 10);
auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL);
size_t record_len;
unsigned char* record = g_base64_decode(record_b64, &record_len);
auto_guchar guchar* record = g_base64_decode(record_b64, &record_len);
signal_buffer* buffer = signal_buffer_create(record, record_len);
g_free(record);
g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer);
}
}

View File

@ -211,7 +211,7 @@ otr_on_connect(ProfAccount* account)
jid = strdup(account->jid);
log_info("Loading OTR key for %s", jid);
gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
auto_gchar gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
if (!otr_dir) {
log_error("Could not create directory for account %s.", jid);
cons_show_error("Could not create directory for account %s.", jid);
@ -236,7 +236,6 @@ otr_on_connect(ProfAccount* account)
if (err != GPG_ERR_NO_ERROR) {
log_warning("Failed to read OTR private key file: %s", keysfilename->str);
cons_show_error("Failed to read OTR private key file: %s", keysfilename->str);
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
return;
}
@ -245,7 +244,6 @@ otr_on_connect(ProfAccount* account)
if (!privkey) {
log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str);
cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str);
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
return;
}
@ -263,7 +261,6 @@ otr_on_connect(ProfAccount* account)
err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
if (err != GPG_ERR_NO_ERROR) {
log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str);
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
g_string_free(fpsfilename, TRUE);
return;
@ -277,7 +274,6 @@ otr_on_connect(ProfAccount* account)
cons_show("Loaded OTR private key for %s", jid);
}
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
g_string_free(fpsfilename, TRUE);
return;
@ -373,7 +369,7 @@ otr_keygen(ProfAccount* account)
jid = strdup(account->jid);
log_info("Generating OTR key for %s", jid);
gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
auto_gchar gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
if (!otr_dir) {
log_error("Could not create directory for account %s.", jid);
@ -391,7 +387,6 @@ otr_keygen(ProfAccount* account)
ui_update();
err = otrl_privkey_generate(user_state, keysfilename->str, account->jid, "xmpp");
if (err != GPG_ERR_NO_ERROR) {
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
log_error("Failed to generate private key");
cons_show_error("Failed to generate private key");
@ -406,7 +401,6 @@ otr_keygen(ProfAccount* account)
log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid);
err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str);
if (err != GPG_ERR_NO_ERROR) {
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
log_error("Failed to create fingerprints file");
cons_show_error("Failed to create fingerprints file");
@ -416,7 +410,6 @@ otr_keygen(ProfAccount* account)
err = otrl_privkey_read(user_state, keysfilename->str);
if (err != GPG_ERR_NO_ERROR) {
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
log_error("Failed to load private key");
data_loaded = FALSE;
@ -425,7 +418,6 @@ otr_keygen(ProfAccount* account)
err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
if (err != GPG_ERR_NO_ERROR) {
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
log_error("Failed to load fingerprints");
data_loaded = FALSE;
@ -434,7 +426,6 @@ otr_keygen(ProfAccount* account)
data_loaded = TRUE;
g_free(otr_dir);
g_string_free(keysfilename, TRUE);
g_string_free(fpsfilename, TRUE);
return;

View File

@ -191,11 +191,10 @@ p_gpg_on_connect(const char* const barejid)
for (int i = 0; i < len; i++) {
GError* gerr = NULL;
gchar* jid = jids[i];
gchar* keyid = g_key_file_get_string(pubkeyfile, jid, "keyid", &gerr);
auto_gchar gchar* keyid = g_key_file_get_string(pubkeyfile, jid, "keyid", &gerr);
if (gerr) {
log_error("Error loading PGP key id for %s", jid);
g_error_free(gerr);
g_free(keyid);
} else {
gpgme_key_t key = NULL;
error = gpgme_get_key(ctx, keyid, &key, 0);
@ -208,7 +207,6 @@ p_gpg_on_connect(const char* const barejid)
pubkeyid->id = strdup(keyid);
pubkeyid->received = FALSE;
g_hash_table_replace(pubkeys, strdup(jid), pubkeyid);
g_free(keyid);
gpgme_key_unref(key);
}
}
@ -978,8 +976,7 @@ static void
_save_pubkeys(void)
{
gsize g_data_size;
gchar* g_pubkeys_data = g_key_file_to_data(pubkeyfile, &g_data_size, NULL);
auto_gchar gchar* g_pubkeys_data = g_key_file_to_data(pubkeyfile, &g_data_size, NULL);
g_file_set_contents(pubsloc, g_pubkeys_data, g_data_size, NULL);
g_chmod(pubsloc, S_IRUSR | S_IWUSR);
g_free(g_pubkeys_data);
}

View File

@ -525,9 +525,8 @@ c_api_init(void)
static char*
_c_plugin_name(const char* filename)
{
gchar* name = g_strndup(filename, strlen(filename) - 1);
auto_gchar gchar* name = g_strndup(filename, strlen(filename) - 1);
gchar* result = g_strdup_printf("%sso", name);
g_free(name);
return result;
}

View File

@ -75,7 +75,7 @@ theme_item_t
plugin_themes_get(const char* const group, const char* const key, const char* const def)
{
if (group && key && g_key_file_has_key(themes, group, key, NULL)) {
gchar* result = g_key_file_get_string(themes, group, key, NULL);
auto_gchar gchar* result = g_key_file_get_string(themes, group, key, NULL);
theme_item_t ret;
@ -148,8 +148,6 @@ plugin_themes_get(const char* const group, const char* const key, const char* co
else
ret = THEME_TEXT;
g_free(result);
return ret;
} else {

View File

@ -303,11 +303,10 @@ get_start(const char* const string, int tokens)
gunichar curr_uni = g_utf8_get_char(curr_ch);
if (num_tokens < tokens) {
gchar* uni_char = g_malloc(7);
auto_gchar gchar* uni_char = g_malloc(7);
int len = g_unichar_to_utf8(curr_uni, uni_char);
uni_char[len] = '\0';
g_string_append(result, uni_char);
g_free(uni_char);
}
if (curr_uni == ' ') {
if (!in_quotes) {

View File

@ -562,10 +562,9 @@ _inp_rl_startup_hook(void)
rl_variable_bind("disable-completion", "on");
// check for and load ~/.config/profanity/inputrc
gchar* inputrc = files_get_inputrc_file();
auto_gchar gchar* inputrc = files_get_inputrc_file();
if (inputrc) {
rl_read_init_file(inputrc);
g_free(inputrc);
}
return 0;
@ -948,7 +947,7 @@ _inp_rl_send_to_editor(int count, int key)
return 0;
}
gchar* message = NULL;
auto_gchar gchar* message = NULL;
if (get_message_from_editor(rl_line_buffer, &message)) {
return 0;
@ -958,7 +957,6 @@ _inp_rl_send_to_editor(int count, int key)
ui_resize();
rl_point = rl_end;
rl_forced_update_display();
g_free(message);
return 0;
}

View File

@ -77,9 +77,8 @@ notifier_uninit(void)
void
notify_typing(const char* const name)
{
gchar* message = g_strdup_printf("%s: typing…", name);
auto_gchar gchar* message = g_strdup_printf("%s: typing…", name);
notify(message, 10000, "Incoming message");
g_free(message);
}
void

View File

@ -79,9 +79,8 @@ _get_icons(void)
#endif /* ICONS_PATH */
gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
auto_gchar gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
icons_dir = g_string_new(icons_dir_s);
g_free(icons_dir_s);
GError* err = NULL;
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {

View File

@ -691,12 +691,12 @@ win_page_down(ProfWin* window)
if ((*page_start == y || (*page_start == page_space && *page_start >= y)) && window->type == WIN_CHAT) {
int bf_size = buffer_size(window->layout->buffer);
if (bf_size > 0) {
char* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
auto_gchar gchar* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
GDateTime* now = g_date_time_new_now_local();
char* end = g_date_time_format_iso8601(now);
gchar* end = g_date_time_format_iso8601(now);
// end is free'd inside
chatwin_db_history((ProfChatWin*)window, start, end, FALSE);
g_free(start);
g_date_time_unref(now);
}
}
@ -1788,7 +1788,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
int colour = theme_attrs(THEME_ME);
size_t indent = 0;
char* time_pref = NULL;
auto_gchar gchar* time_pref = NULL;
switch (window->type) {
case WIN_CHAT:
time_pref = prefs_get_string(PREF_TIME_CHAT);
@ -1810,13 +1810,12 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
break;
}
gchar* date_fmt = NULL;
auto_gchar gchar* date_fmt = NULL;
if (g_strcmp0(time_pref, "off") == 0 || time == NULL) {
date_fmt = g_strdup("");
} else {
date_fmt = g_date_time_format(time, time_pref);
}
g_free(time_pref);
assert(date_fmt != NULL);
if (strlen(date_fmt) != 0) {
@ -1903,8 +1902,6 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
wattroff(window->layout->win, theme_attrs(theme_item));
}
}
g_free(date_fmt);
}
static void
@ -2309,21 +2306,17 @@ win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previo
return NULL;
}
char* result = autocomplete_complete(window->quotes_ac, input + 1, FALSE, previous);
auto_gchar gchar* result = autocomplete_complete(window->quotes_ac, input + 1, FALSE, previous);
if (result == NULL) {
return NULL;
}
gchar** parts = g_strsplit(result, "\n", -1);
gchar* quoted_result = g_strjoinv("\n> ", parts);
auto_gcharv gchar** parts = g_strsplit(result, "\n", -1);
auto_gchar gchar* quoted_result = g_strjoinv("\n> ", parts);
GString* replace_with = g_string_new("> ");
g_string_append(replace_with, quoted_result);
g_string_append(replace_with, "\n");
g_free(result);
g_free(quoted_result);
g_strfreev(parts);
return g_string_free(replace_with, FALSE);
}

View File

@ -1318,7 +1318,7 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
g_regex_match(regex, message->plain, 0, &match_info);
while (g_match_info_matches(match_info)) {
gchar* word = g_match_info_fetch(match_info, 0);
auto_gchar gchar* word = g_match_info_fetch(match_info, 0);
if (flip) {
autocomplete_add_unsorted(win->urls_ac, word, FALSE);
@ -1328,7 +1328,6 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
// for people who run profanity a long time, we don't want to waste a lot of memory
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
g_free(word);
g_match_info_next(match_info, NULL);
}

View File

@ -65,7 +65,7 @@ static GHashTable* jid_to_ver;
static GHashTable* jid_to_caps;
static GHashTable* prof_features;
static char* my_sha1;
static gchar* my_sha1;
static void _save_cache(void);
static EntityCapabilities* _caps_by_ver(const char* const ver);