commit 43934a84fa58d0706d47adfafa3767d24c4df5d7
parent e856ff6f2e3a20f91c611cba0cb464fcfec865fd
Author: in0rdr <andreas.gruhler@uzh.ch>
Date: Wed, 23 Nov 2016 15:33:30 +0800
Fix memory leak
Diffstat:
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/diary.c b/diary.c
@@ -90,10 +90,7 @@ bool is_leap(int year) {
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
-void read_diary(char* dir) {
- int width = COLS - ASIDE_WIDTH - CAL_WIDTH;
- WINDOW* prev = newwin(LINES - 1, width, 1, ASIDE_WIDTH + CAL_WIDTH);
-
+WINDOW* read_diary(char* dir, WINDOW* prev, int width) {
wclear(prev);
char buff[width];
int i = 0;
@@ -108,6 +105,8 @@ void read_diary(char* dir) {
fclose(fp);
}
wrefresh(prev);
+
+ return prev;
}
bool go_to(WINDOW* calendar, WINDOW* month_sidebar, time_t date, int* cur_pad_pos) {
@@ -211,11 +210,14 @@ int main(int argc, char** argv) {
// init the current pad possition at the very end,
// such that the cursor is displayed top of screen
int pad_pos = 9999999;
+ int width = COLS - ASIDE_WIDTH - CAL_WIDTH;
wmove(cal, 0, 0);
getyx(cal, cy, cx);
bool ret = go_to(cal, aside, raw_time, &pad_pos);
- read_diary(diary_dir);
+
+ WINDOW* prev = newwin(LINES - 1, width, 1, ASIDE_WIDTH + CAL_WIDTH);
+ prev = read_diary(diary_dir, prev, width);
do {
ch = wgetch(cal);
@@ -285,7 +287,7 @@ int main(int argc, char** argv) {
if (ret) {
update_date(date_header);
- read_diary(diary_dir);
+ prev = read_diary(diary_dir, prev, width);
}
} while (ch != 'q');