diff options
author | Frederic Culot <calcurse@culot.org> | 2009-06-21 15:19:21 +0000 |
---|---|---|
committer | Frederic Culot <calcurse@culot.org> | 2009-06-21 15:19:21 +0000 |
commit | bff0d973a426a5c9b55e824ab2a11560a2245938 (patch) | |
tree | d3729cf77655efc715e1258201fa71f6a37ad6a8 /src/notify.c | |
parent | bc44508a10434b18ca3d231d58882995a4d6d2ad (diff) | |
download | calcurse-bff0d973a426a5c9b55e824ab2a11560a2245938.tar.gz calcurse-bff0d973a426a5c9b55e824ab2a11560a2245938.zip |
Fixed a memory leak caused by a wrong usage of the notify_app structure
Diffstat (limited to 'src/notify.c')
-rwxr-xr-x | src/notify.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/notify.c b/src/notify.c index 32ea3e7..03eca79 100755 --- a/src/notify.c +++ b/src/notify.c @@ -1,4 +1,4 @@ -/* $calcurse: notify.c,v 1.37 2009/06/21 14:42:49 culot Exp $ */ +/* $calcurse: notify.c,v 1.38 2009/06/21 15:19:21 culot Exp $ */ /* * Calcurse - text-based organizer @@ -45,6 +45,21 @@ static struct notify_app_s notify_app; static pthread_attr_t detached_thread_attr; static pthread_t notify_t_main; +/* + * This is used to update the notify_app structure. + * Note: the mutex associated with this structure must be locked by the + * caller! + */ +static void +notify_update_app (long start, char state, char *msg) +{ + notify_free_app (); + notify_app.got_app = 1; + notify_app.time = start; + notify_app.state = state; + notify_app.txt = mem_strdup (msg); +} + /* Return 1 if we need to display the notify-bar, else 0. */ int notify_bar (void) @@ -108,6 +123,7 @@ notify_init_bar (void) pthread_mutex_init (¬ify.mutex, NULL); pthread_mutex_init (¬ify_app.mutex, NULL); notify_app.got_app = 0; + notify_app.txt = 0; notify.win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x); extract_aptsfile (); } @@ -118,7 +134,7 @@ notify_init_bar (void) void notify_free_app (void) { - if (notify_app.got_app && notify_app.txt) + if (notify_app.txt) mem_free (notify_app.txt); } @@ -302,14 +318,13 @@ notify_thread_app (void *arg) pthread_mutex_lock (¬ify_app.mutex); if (tmp_app.got_app) { - notify_app.got_app = 1; - notify_app.time = tmp_app.time; - notify_app.txt = mem_strdup (tmp_app.txt); - notify_app.state = tmp_app.state; + notify_update_app (tmp_app.time, tmp_app.state, tmp_app.txt); } else { + notify_free_app (); notify_app.got_app = 0; + notify_app.txt = 0; } pthread_mutex_unlock (¬ify_app.mutex); @@ -356,10 +371,7 @@ notify_check_added (char *mesg, long start, char state) if (update_notify) { - notify_app.got_app = 1; - notify_app.time = start; - notify_app.txt = mem_strdup (mesg); - notify_app.state = state; + notify_update_app (start, state, mesg); } pthread_mutex_unlock (¬ify_app.mutex); notify_update_bar (); @@ -395,10 +407,7 @@ notify_check_repeated (recur_apoint_llist_node_t *i) } if (update_notify) { - notify_app.got_app = 1; - notify_app.time = real_app_time; - notify_app.txt = mem_strdup (i->mesg); - notify_app.state = i->state; + notify_update_app (real_app_time, i->state, i->mesg); } pthread_mutex_unlock (¬ify_app.mutex); notify_update_bar (); |