about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2013-08-24 00:39:03 +0300
committerDmitry Podgorny <pasis.ua@gmail.com>2013-08-24 00:39:03 +0300
commit021d0955368272456434db4061e6c6b15bbd77db (patch)
treeb5d0a9bde1aacad539c50840162d79ad3254a45f /src/ui
parent1ef361684f8c6b892df9a364265c7ffa7d57adbd (diff)
downloadprofani-tty-021d0955368272456434db4061e6c6b15bbd77db.tar.gz
small refactoring in statusbar.c
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/statusbar.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c
index cd218e73..6e7eae30 100644
--- a/src/ui/statusbar.c
+++ b/src/ui/statusbar.c
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 
@@ -63,6 +64,8 @@ create_status_bar(void)
     mvwprintw(status_bar, 0, cols - 31, _active);
     wattroff(status_bar, COLOUR_STATUS_BRACKET);
 
+    if (last_time != NULL)
+        g_date_time_unref(last_time);
     last_time = g_date_time_new_now_local();
 
     dirty = TRUE;
@@ -76,6 +79,8 @@ status_bar_refresh(void)
 
     if (elapsed >= 60000000) {
         dirty = TRUE;
+        if (last_time != NULL)
+            g_date_time_unref(last_time);
         last_time = g_date_time_new_now_local();
     }
 
@@ -113,6 +118,8 @@ status_bar_resize(void)
     if (message != NULL)
         mvwprintw(status_bar, 0, 10, message);
 
+    if (last_time != NULL)
+        g_date_time_unref(last_time);
     last_time = g_date_time_new_now_local();
     dirty = TRUE;
 }
@@ -184,13 +191,11 @@ status_bar_get_password(void)
 void
 status_bar_print_message(const char * const msg)
 {
+    werase(status_bar);
+
     if (message != NULL) {
         free(message);
-        message = NULL;
     }
-
-    werase(status_bar);
-
     message = (char *) malloc(strlen(msg) + 1);
     strcpy(message, msg);
     mvwprintw(status_bar, 0, 10, message);
@@ -270,6 +275,7 @@ static void
 _status_bar_update_time(void)
 {
     gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
+    assert(date_fmt != NULL);
 
     wattron(status_bar, COLOUR_STATUS_BRACKET);
     mvwaddch(status_bar, 0, 1, '[');
@@ -279,7 +285,7 @@ _status_bar_update_time(void)
     mvwaddch(status_bar, 0, 7, ']');
     wattroff(status_bar, COLOUR_STATUS_BRACKET);
 
-    free(date_fmt);
+    g_free(date_fmt);
 
     dirty = TRUE;
 }