about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-07-17 23:10:15 +0200
committerGitHub <noreply@github.com>2021-07-17 23:10:15 +0200
commitba414eb0aca2a4178cbf5244e8c266f213cb4497 (patch)
tree177fa9db1bea16888647b351b374002eb6f91281
parent1511e921d2ac171fc790368f8fcfff4e88493f72 (diff)
parentafdae6ac029618f51bba586d0ee612326118ee47 (diff)
downloadprofani-tty-ba414eb0aca2a4178cbf5244e8c266f213cb4497.tar.gz
Merge pull request #1583 from profanity-im/memleak
Fix memory leak in accounts_get_login_status()
-rw-r--r--src/config/accounts.c4
-rw-r--r--src/event/server_events.c19
2 files changed, 11 insertions, 12 deletions
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 774adc0d..6018cfff 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -958,6 +958,10 @@ accounts_get_login_status(const char* const account_name)
     if (g_strcmp0(setting, "last") == 0) {
         status = accounts_get_last_status(account_name);
     }
+
+    if (setting) {
+        g_free(setting);
+    }
     return status;
 }
 
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 7e5e3d7d..a61aecf6 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -168,8 +168,9 @@ sv_ev_roster_received(void)
     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);
-    if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) {
+    int diff_secs = 0;
 
+    if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) {
         GTimeVal lasttv;
         GDateTime* nowdt = g_date_time_new_now_utc();
         gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
@@ -177,23 +178,17 @@ sv_ev_roster_received(void)
         if (res) {
             GDateTime* lastdt = g_date_time_new_from_timeval_utc(&lasttv);
             GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
-            int diff_secs = (diff_micros / 1000) / 1000;
-
-            connection_set_presence_msg(status_message);
-            cl_ev_presence_send(conn_presence, diff_secs);
 
+            diff_secs = (diff_micros / 1000) / 1000;
             g_date_time_unref(lastdt);
-        } else {
-            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);
     }
+    connection_set_presence_msg(status_message);
+    cl_ev_presence_send(conn_presence, diff_secs);
 
-    free(last_activity_str);
+    g_free(status_message);
+    g_free(last_activity_str);
 
     const char* fulljid = connection_get_fulljid();
     plugins_on_connect(account_name, fulljid);