From 26f3f2c2f1cb890c9779d35ad807f32745b03415 Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Tue, 20 Jul 2010 11:42:30 -0400 Subject: [PATCH] [#3218] Free memory when ending call in gnome client --- sflphone-client-gnome/src/actions.c | 1 + sflphone-client-gnome/src/callable_obj.c | 21 +++++++++++++++++++ sflphone-client-gnome/src/callable_obj.h | 2 ++ sflphone-client-gnome/src/contacts/calltree.c | 11 ---------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/sflphone-client-gnome/src/actions.c b/sflphone-client-gnome/src/actions.c index 846eaf0c62..92c216aa43 100644 --- a/sflphone-client-gnome/src/actions.c +++ b/sflphone-client-gnome/src/actions.c @@ -185,6 +185,7 @@ sflphone_hung_up( callable_obj_t * c) calltree_remove_call(current_calls, c, NULL); c->_state = CALL_STATE_DIALING; call_remove_all_errors(c); + free_callable_obj_t(c); update_actions(); #if GTK_CHECK_VERSION(2,10,0) status_tray_icon_blink( FALSE ); diff --git a/sflphone-client-gnome/src/callable_obj.c b/sflphone-client-gnome/src/callable_obj.c index 2cfeb7a1a1..d34564b971 100644 --- a/sflphone-client-gnome/src/callable_obj.c +++ b/sflphone-client-gnome/src/callable_obj.c @@ -129,6 +129,19 @@ void call_remove_all_errors(callable_obj_t * call) g_ptr_array_foreach (call->_error_dialogs, (GFunc) gtk_widget_destroy, NULL); } +void *threaded_clock_incrementer(void *pc) { + + int count = 0; + + callable_obj_t *call = (callable_obj_t *)pc; + + while(call->clockStarted) { + DEBUG("Clock started: %d", call->clockStarted); + DEBUG("Clock: %d\n", count++); + sleep(1); + } +} + void create_new_call (callable_type_t type, call_state_t state, gchar* callID , gchar* accountID, gchar* peer_name, gchar* peer_number, callable_obj_t ** new_call) { @@ -162,6 +175,10 @@ void create_new_call (callable_type_t type, call_state_t state, gchar* callID , obj->_callID = g_strdup (call_id); obj->_confID = NULL; + obj->clockStarted = 1; + + pthread_create(&(obj->tid), NULL, threaded_clock_incrementer, obj); + *new_call = obj; } @@ -255,6 +272,10 @@ void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details void free_callable_obj_t (callable_obj_t *c) { + c->clockStarted = 0; + + pthread_join(c->tid, NULL); + g_free (c->_callID); g_free (c->_accountID); g_free (c->_peer_name); diff --git a/sflphone-client-gnome/src/callable_obj.h b/sflphone-client-gnome/src/callable_obj.h index 21f46fe55e..414245854f 100644 --- a/sflphone-client-gnome/src/callable_obj.h +++ b/sflphone-client-gnome/src/callable_obj.h @@ -154,6 +154,8 @@ typedef struct { // thread id to increment clock pthread_t tid; + int clockStarted; + } callable_obj_t; void create_new_call (callable_type_t, call_state_t, gchar*, gchar*, gchar*, gchar*, callable_obj_t **); diff --git a/sflphone-client-gnome/src/contacts/calltree.c b/sflphone-client-gnome/src/contacts/calltree.c index 11da3e3f12..34a615acab 100644 --- a/sflphone-client-gnome/src/contacts/calltree.c +++ b/sflphone-client-gnome/src/contacts/calltree.c @@ -74,17 +74,6 @@ enum { COLUMN_ACCOUNT_PTR, }; - -void *threaded_clock_incrementer(void *call) { - - int count = 0; - - while(1) { - printf("Clock: %d\n", count++); - sleep(1); - } -} - /** * Show popup menu */ -- GitLab