delwin() and dereferencing issue in viewer, #70
[smdp.git] / src / viewer.c
index 38985ae..50646d7 100644 (file)
@@ -93,11 +93,14 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) {
         lc = 0;
         line = slide->line;
 
-        while(line) {
+        while(line && line->text) {
 
-            if (line && line->text && line->text->text)
+            if (line->text->text)
                 lc += url_count_inline(line->text->text);
 
+            if (line->text->text)
+                line->length -= url_len_inline(line->text->text);
+
             if(line->length > COLS) {
                 i = line->length;
                 offset = 0;
@@ -412,8 +415,13 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) {
         url_purge();
     }
 
+    // disable ncurses
     endwin();
 
+    // free ncurses memory
+    delwin(content);
+    delwin(stdscr);
+
     return 0;
 }
 
@@ -670,7 +678,7 @@ void inline_display(WINDOW *window, const char *c, const int colors) {
 
                             url_num = url_add(start_link_name, length_link_name, start_url, i - start_url, 0,0);
 
-                            wprintw(window, "[%d]", url_num);
+                            wprintw(window, " [%d]", url_num);
 
                             // turn highlighting and underlining off
                             wattroff(window, A_UNDERLINE);