fix memory leaks in tog display code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/tog/tog.c b/tog/tog.c
index 588d1b0..a5ab060 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -897,6 +897,7 @@ draw_file(WINDOW *window, FILE *f, int *first_displayed_line,
err = format_line(&wline, &width, line, COLS);
if (err) {
free(line);
+ free(wline);
return err;
}
waddwstr(window, wline);
@@ -905,6 +906,8 @@ draw_file(WINDOW *window, FILE *f, int *first_displayed_line,
if (++nprinted == 1)
*first_displayed_line = nlines;
free(line);
+ free(wline);
+ wline = NULL;
}
*last_displayed_line = nlines;
@@ -1118,7 +1121,10 @@ draw_blame(WINDOW *window, struct got_object_id *id, FILE *f, const char *path,
err = format_line(&wline, &width, line, COLS);
free(line);
+ line = NULL;
waddwstr(window, wline);
+ free(wline);
+ wline = NULL;
if (width < COLS)
waddch(window, '\n');
@@ -1131,9 +1137,12 @@ draw_blame(WINDOW *window, struct got_object_id *id, FILE *f, const char *path,
free(id_str);
err = format_line(&wline, &width, line, COLS);
free(line);
+ line = NULL;
if (err)
return err;
waddwstr(window, wline);
+ free(wline);
+ wline = NULL;
if (width < COLS)
waddch(window, '\n');
@@ -1168,6 +1177,7 @@ draw_blame(WINDOW *window, struct got_object_id *id, FILE *f, const char *path,
err = got_object_id_str(&id_str, blame_line->id);
if (err) {
free(line);
+ free(wline);
return err;
}
wprintw(window, "%.8s ", id_str);
@@ -1188,6 +1198,8 @@ draw_blame(WINDOW *window, struct got_object_id *id, FILE *f, const char *path,
if (++nprinted == 1)
*first_displayed_line = lineno;
free(line);
+ free(wline);
+ wline = NULL;
}
*last_displayed_line = lineno;
@@ -1810,6 +1822,8 @@ draw_tree_entries(struct got_tree_entry **first_displayed_entry,
if (err)
return err;
waddwstr(window, wline);
+ free(wline);
+ wline = NULL;
if (width < COLS)
waddch(window, '\n');
if (--limit <= 0)
@@ -1818,6 +1832,8 @@ draw_tree_entries(struct got_tree_entry **first_displayed_entry,
if (err)
return err;
waddwstr(window, wline);
+ free(wline);
+ wline = NULL;
if (width < COLS)
waddch(window, '\n');
if (--limit <= 0)
@@ -1874,6 +1890,8 @@ draw_tree_entries(struct got_tree_entry **first_displayed_entry,
if (n == selected)
wstandend(window);
free(line);
+ free(wline);
+ wline = NULL;
n++;
(*ndisplayed)++;
*last_displayed_entry = te;