Fixed a memory leak caused by a wrong usage of the notify_app structure
This commit is contained in:
parent
bc44508a10
commit
bff0d973a4
@ -5,6 +5,9 @@
|
|||||||
* src/utils.c (exit_calcurse): free memory associated with
|
* src/utils.c (exit_calcurse): free memory associated with
|
||||||
structure used for appointments notification
|
structure used for appointments notification
|
||||||
|
|
||||||
|
* src/utils.c: fixed a memory leak caused by a wrong usage of the
|
||||||
|
notify_app structure
|
||||||
|
|
||||||
2009-06-20 Frederic Culot <frederic@culot.org>
|
2009-06-20 Frederic Culot <frederic@culot.org>
|
||||||
|
|
||||||
* src/custom.c (set_confwin_attr): new function
|
* src/custom.c (set_confwin_attr): new function
|
||||||
|
37
src/notify.c
37
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
|
* Calcurse - text-based organizer
|
||||||
@ -45,6 +45,21 @@ static struct notify_app_s notify_app;
|
|||||||
static pthread_attr_t detached_thread_attr;
|
static pthread_attr_t detached_thread_attr;
|
||||||
static pthread_t notify_t_main;
|
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. */
|
/* Return 1 if we need to display the notify-bar, else 0. */
|
||||||
int
|
int
|
||||||
notify_bar (void)
|
notify_bar (void)
|
||||||
@ -108,6 +123,7 @@ notify_init_bar (void)
|
|||||||
pthread_mutex_init (¬ify.mutex, NULL);
|
pthread_mutex_init (¬ify.mutex, NULL);
|
||||||
pthread_mutex_init (¬ify_app.mutex, NULL);
|
pthread_mutex_init (¬ify_app.mutex, NULL);
|
||||||
notify_app.got_app = 0;
|
notify_app.got_app = 0;
|
||||||
|
notify_app.txt = 0;
|
||||||
notify.win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
|
notify.win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
|
||||||
extract_aptsfile ();
|
extract_aptsfile ();
|
||||||
}
|
}
|
||||||
@ -118,7 +134,7 @@ notify_init_bar (void)
|
|||||||
void
|
void
|
||||||
notify_free_app (void)
|
notify_free_app (void)
|
||||||
{
|
{
|
||||||
if (notify_app.got_app && notify_app.txt)
|
if (notify_app.txt)
|
||||||
mem_free (notify_app.txt);
|
mem_free (notify_app.txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,14 +318,13 @@ notify_thread_app (void *arg)
|
|||||||
pthread_mutex_lock (¬ify_app.mutex);
|
pthread_mutex_lock (¬ify_app.mutex);
|
||||||
if (tmp_app.got_app)
|
if (tmp_app.got_app)
|
||||||
{
|
{
|
||||||
notify_app.got_app = 1;
|
notify_update_app (tmp_app.time, tmp_app.state, tmp_app.txt);
|
||||||
notify_app.time = tmp_app.time;
|
|
||||||
notify_app.txt = mem_strdup (tmp_app.txt);
|
|
||||||
notify_app.state = tmp_app.state;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
notify_free_app ();
|
||||||
notify_app.got_app = 0;
|
notify_app.got_app = 0;
|
||||||
|
notify_app.txt = 0;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock (¬ify_app.mutex);
|
pthread_mutex_unlock (¬ify_app.mutex);
|
||||||
|
|
||||||
@ -356,10 +371,7 @@ notify_check_added (char *mesg, long start, char state)
|
|||||||
|
|
||||||
if (update_notify)
|
if (update_notify)
|
||||||
{
|
{
|
||||||
notify_app.got_app = 1;
|
notify_update_app (start, state, mesg);
|
||||||
notify_app.time = start;
|
|
||||||
notify_app.txt = mem_strdup (mesg);
|
|
||||||
notify_app.state = state;
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock (¬ify_app.mutex);
|
pthread_mutex_unlock (¬ify_app.mutex);
|
||||||
notify_update_bar ();
|
notify_update_bar ();
|
||||||
@ -395,10 +407,7 @@ notify_check_repeated (recur_apoint_llist_node_t *i)
|
|||||||
}
|
}
|
||||||
if (update_notify)
|
if (update_notify)
|
||||||
{
|
{
|
||||||
notify_app.got_app = 1;
|
notify_update_app (real_app_time, i->state, i->mesg);
|
||||||
notify_app.time = real_app_time;
|
|
||||||
notify_app.txt = mem_strdup (i->mesg);
|
|
||||||
notify_app.state = i->state;
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock (¬ify_app.mutex);
|
pthread_mutex_unlock (¬ify_app.mutex);
|
||||||
notify_update_bar ();
|
notify_update_bar ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user