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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user