Some minor improvements
* destroy/free/shutdown/close in reverse order of allocation * more static/auto_Xfree * less variables/strlen/GString * properly `\0`-terminate string of testcase Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -177,9 +177,9 @@ callbacks_remove(const char* const plugin_name)
|
||||
void
|
||||
callbacks_close(void)
|
||||
{
|
||||
g_hash_table_destroy(p_commands);
|
||||
g_hash_table_destroy(p_timed_functions);
|
||||
g_hash_table_destroy(p_window_callbacks);
|
||||
g_hash_table_destroy(p_timed_functions);
|
||||
g_hash_table_destroy(p_commands);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -95,9 +95,9 @@ _plugins_shutdown(void)
|
||||
c_shutdown();
|
||||
#endif
|
||||
|
||||
autocompleters_destroy();
|
||||
plugin_themes_close();
|
||||
plugin_settings_close();
|
||||
plugin_themes_close();
|
||||
autocompleters_destroy();
|
||||
callbacks_close();
|
||||
disco_close();
|
||||
g_hash_table_destroy(plugins);
|
||||
@@ -399,7 +399,7 @@ plugins_reload(const char* const name, GString* error_message)
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
_plugins_unloaded_list_dir(const gchar* const dir, GSList** result)
|
||||
{
|
||||
GDir* plugins_dir = g_dir_open(dir, 0, NULL);
|
||||
|
||||
@@ -100,16 +100,13 @@ python_env_init(void)
|
||||
python_init_prof();
|
||||
|
||||
auto_gchar gchar* plugins_dir = files_get_data_path(DIR_PLUGINS);
|
||||
GString* path = g_string_new("import sys\n");
|
||||
g_string_append(path, "sys.path.append(\"");
|
||||
g_string_append(path, plugins_dir);
|
||||
g_string_append(path, "/\")\n");
|
||||
auto_gchar gchar* path = g_strdup_printf(
|
||||
"import sys\n"
|
||||
"sys.path.append(\"%s/\")\n", plugins_dir);
|
||||
|
||||
PyRun_SimpleString(path->str);
|
||||
PyRun_SimpleString(path);
|
||||
python_check_error();
|
||||
|
||||
g_string_free(path, TRUE);
|
||||
|
||||
allow_python_threads();
|
||||
}
|
||||
|
||||
|
||||
@@ -164,11 +164,6 @@ http_file_put(void* userdata)
|
||||
FILE* fh = NULL;
|
||||
|
||||
auto_char char* err = NULL;
|
||||
gchar* content_type_header;
|
||||
// Optional headers
|
||||
gchar* auth_header = NULL;
|
||||
gchar* cookie_header = NULL;
|
||||
gchar* expires_header = NULL;
|
||||
|
||||
CURL* curl;
|
||||
CURLcode res;
|
||||
@@ -177,15 +172,14 @@ http_file_put(void* userdata)
|
||||
upload->bytes_sent = 0;
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
gchar* msg = g_strdup_printf("Uploading '%s': 0%%", upload->filename);
|
||||
auto_gchar gchar* msg = g_strdup_printf("Uploading '%s': 0%%", upload->filename);
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_print_http_transfer(upload->window, msg, upload->put_url);
|
||||
g_free(msg);
|
||||
|
||||
auto_gchar gchar* cert_path = prefs_get_string(PREF_TLS_CERTPATH);
|
||||
gchar* cafile = cafile_get_name();
|
||||
auto_gchar gchar* cafile = cafile_get_name();
|
||||
gboolean insecure = FALSE;
|
||||
ProfAccount* account = accounts_get_account(session_get_account_name());
|
||||
if (account) {
|
||||
@@ -201,7 +195,7 @@ http_file_put(void* userdata)
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
|
||||
struct curl_slist* headers = NULL;
|
||||
content_type_header = g_strdup_printf("Content-Type: %s", upload->mime_type);
|
||||
auto_gchar gchar* content_type_header = g_strdup_printf("Content-Type: %s", upload->mime_type);
|
||||
if (!content_type_header) {
|
||||
content_type_header = g_strdup(FALLBACK_CONTENTTYPE_HEADER);
|
||||
}
|
||||
@@ -209,6 +203,7 @@ http_file_put(void* userdata)
|
||||
headers = curl_slist_append(headers, "Expect:");
|
||||
|
||||
// Optional headers
|
||||
auto_gchar gchar* auth_header = NULL;
|
||||
if (upload->authorization) {
|
||||
auth_header = g_strdup_printf("Authorization: %s", upload->authorization);
|
||||
if (!auth_header) {
|
||||
@@ -216,6 +211,7 @@ http_file_put(void* userdata)
|
||||
}
|
||||
headers = curl_slist_append(headers, auth_header);
|
||||
}
|
||||
auto_gchar gchar* cookie_header = NULL;
|
||||
if (upload->cookie) {
|
||||
cookie_header = g_strdup_printf("Cookie: %s", upload->cookie);
|
||||
if (!cookie_header) {
|
||||
@@ -223,6 +219,7 @@ http_file_put(void* userdata)
|
||||
}
|
||||
headers = curl_slist_append(headers, cookie_header);
|
||||
}
|
||||
auto_gchar gchar* expires_header = NULL;
|
||||
if (upload->expires) {
|
||||
expires_header = g_strdup_printf("Expires: %s", upload->expires);
|
||||
if (!expires_header) {
|
||||
@@ -297,13 +294,8 @@ http_file_put(void* userdata)
|
||||
fclose(fh);
|
||||
}
|
||||
free(output.buffer);
|
||||
g_free(content_type_header);
|
||||
g_free(auth_header);
|
||||
g_free(cookie_header);
|
||||
g_free(expires_header);
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
g_free(cafile);
|
||||
|
||||
if (err) {
|
||||
gchar* msg;
|
||||
|
||||
@@ -160,12 +160,11 @@ cons_bad_cmd_usage(const char* const cmd)
|
||||
void
|
||||
cons_show_error(const char* const msg, ...)
|
||||
{
|
||||
ProfWin* console = wins_get_console();
|
||||
va_list arg;
|
||||
va_start(arg, msg);
|
||||
GString* fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
win_println(console, THEME_ERROR, "-", "%s", fmt_msg->str);
|
||||
win_println(wins_get_console(), THEME_ERROR, "-", "%s", fmt_msg->str);
|
||||
g_string_free(fmt_msg, TRUE);
|
||||
va_end(arg);
|
||||
|
||||
|
||||
@@ -93,7 +93,6 @@ static void
|
||||
_ui_close(void)
|
||||
{
|
||||
g_timer_destroy(ui_idle_time);
|
||||
endwin();
|
||||
notifier_uninit();
|
||||
cons_clear_alerts();
|
||||
wins_destroy();
|
||||
@@ -102,6 +101,7 @@ _ui_close(void)
|
||||
free_title_bar();
|
||||
delwin(main_scr);
|
||||
delscreen(set_term(NULL));
|
||||
endwin();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -69,8 +69,8 @@ static void
|
||||
_chat_session_free(ChatSession* session)
|
||||
{
|
||||
if (session) {
|
||||
free(session->barejid);
|
||||
free(session->resource);
|
||||
free(session->barejid);
|
||||
free(session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2571,7 +2571,8 @@ iq_send_stanza(xmpp_stanza_t* const stanza)
|
||||
if (plugin_text) {
|
||||
xmpp_send_raw_string(conn, "%s", plugin_text);
|
||||
} else {
|
||||
xmpp_send_raw_string(conn, "%s", text);
|
||||
/* libstrophe does the strlen for us, so simply always pass SIZE_MAX */
|
||||
xmpp_send_raw(conn, text, SIZE_MAX);
|
||||
}
|
||||
xmpp_free(connection_get_ctx(), text);
|
||||
}
|
||||
|
||||
@@ -546,7 +546,7 @@ prof_occurrences_of_large_message_tests(void** state)
|
||||
char* haystack = malloc(haystack_sz);
|
||||
const char needle[] = "needle ";
|
||||
while (haystack_sz - haystack_cur > sizeof(needle)) {
|
||||
memcpy(&haystack[haystack_cur], needle, sizeof(needle) - 1);
|
||||
memcpy(&haystack[haystack_cur], needle, sizeof(needle));
|
||||
expected = g_slist_append(expected, GINT_TO_POINTER(haystack_cur));
|
||||
haystack_cur += sizeof(needle) - 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user