1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge pull request #1583 from profanity-im/memleak

Fix memory leak in accounts_get_login_status()
This commit is contained in:
Michael Vetter 2021-07-17 23:10:15 +02:00 committed by GitHub
commit ba414eb0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View File

@ -958,6 +958,10 @@ accounts_get_login_status(const char* const account_name)
if (g_strcmp0(setting, "last") == 0) { if (g_strcmp0(setting, "last") == 0) {
status = accounts_get_last_status(account_name); status = accounts_get_last_status(account_name);
} }
if (setting) {
g_free(setting);
}
return status; return status;
} }

View File

@ -168,8 +168,9 @@ sv_ev_roster_received(void)
resource_presence_t conn_presence = accounts_get_login_presence(account_name); resource_presence_t conn_presence = accounts_get_login_presence(account_name);
char* last_activity_str = accounts_get_last_activity(account_name); char* last_activity_str = accounts_get_last_activity(account_name);
char* status_message = accounts_get_login_status(account_name); char* status_message = accounts_get_login_status(account_name);
if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) { int diff_secs = 0;
if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) {
GTimeVal lasttv; GTimeVal lasttv;
GDateTime* nowdt = g_date_time_new_now_utc(); GDateTime* nowdt = g_date_time_new_now_utc();
gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv); gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
@ -177,23 +178,17 @@ sv_ev_roster_received(void)
if (res) { if (res) {
GDateTime* lastdt = g_date_time_new_from_timeval_utc(&lasttv); GDateTime* lastdt = g_date_time_new_from_timeval_utc(&lasttv);
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt); GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
int diff_secs = (diff_micros / 1000) / 1000;
diff_secs = (diff_micros / 1000) / 1000;
g_date_time_unref(lastdt);
}
g_date_time_unref(nowdt);
}
connection_set_presence_msg(status_message); connection_set_presence_msg(status_message);
cl_ev_presence_send(conn_presence, diff_secs); cl_ev_presence_send(conn_presence, diff_secs);
g_date_time_unref(lastdt); g_free(status_message);
} else { g_free(last_activity_str);
connection_set_presence_msg(status_message);
cl_ev_presence_send(conn_presence, 0);
}
g_date_time_unref(nowdt);
} else {
connection_set_presence_msg(status_message);
cl_ev_presence_send(conn_presence, 0);
}
free(last_activity_str);
const char* fulljid = connection_get_fulljid(); const char* fulljid = connection_get_fulljid();
plugins_on_connect(account_name, fulljid); plugins_on_connect(account_name, fulljid);