Commit d68cfb8c authored by jehan's avatar jehan

adapt code to new object ref management

parent 3e3d151c
......@@ -195,6 +195,13 @@ void _belle_sip_object_copy(belle_sip_object_t *newobj, const belle_sip_object_t
**/
belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj);
/**
* Same as #belle_sip_object_clone but with ref count set to 1
*
**/
belle_sip_object_t *belle_sip_object_clone_and_ref(const belle_sip_object_t *obj);
/**
* Returns a string describing the inheritance diagram and implemented interfaces of object obj.
**/
......
This diff is collapsed.
......@@ -43,7 +43,7 @@ void belle_sip_header_init(belle_sip_header_t *header) {
static void belle_sip_header_clone(belle_sip_header_t *header, const belle_sip_header_t *orig){
CLONE_STRING(belle_sip_header,name,header,orig)
if (belle_sip_header_get_next(orig)) {
belle_sip_header_set_next(header,BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_get_next(orig))))) ;
belle_sip_header_set_next(header,BELLE_SIP_HEADER(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(belle_sip_header_get_next(orig))))) ;
}
}
static void belle_sip_header_destroy(belle_sip_header_t *header){
......
......@@ -262,7 +262,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){
char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s);
s->expired=TRUE;
belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
if (s->timeout>0)/*to avoid too many traces*/ belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
belle_sip_free(objdesc);
ret=s->notify(s->data,revents);
if (ret==0){
......
......@@ -214,7 +214,9 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
return newobj;
}
belle_sip_object_t *belle_sip_object_clone_and_ref(const belle_sip_object_t *obj) {
return belle_sip_object_ref(belle_sip_object_clone(obj));
}
void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno){
if (obj!=NULL){
......
......@@ -54,6 +54,7 @@ static void belle_sip_channel_destroy(belle_sip_channel_t *obj){
belle_sip_free(obj->peer_name);
if (obj->local_ip) belle_sip_free(obj->local_ip);
obj->listeners=for_each_weak_unref_free(obj->listeners,(belle_sip_object_destroy_notify_t)belle_sip_channel_remove_listener,obj);
belle_sip_message("channel [%p] destroyed",obj);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_channel_t);
......
......@@ -30,8 +30,13 @@ void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_s
static void belle_sip_listening_point_uninit(belle_sip_listening_point_t *lp){
belle_sip_listening_point_clean_channels(lp);
belle_sip_message("Listening [%p] on [%s://%s:%i] destroyed" ,lp
,belle_sip_uri_get_transport_param(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_host(BELLE_SIP_LISTENING_POINT(lp)->listening_uri)
,belle_sip_uri_get_port(BELLE_SIP_LISTENING_POINT(lp)->listening_uri));
belle_sip_object_unref(lp->listening_uri);
lp->channel_listener=NULL; /*does not unref provider*/
}
......@@ -55,12 +60,17 @@ void belle_sip_listening_point_remove_channel(belle_sip_listening_point_t *lp, b
belle_sip_object_unref(chan);
}
void belle_sip_listening_point_clean_channels(belle_sip_listening_point_t *lp){
int existing_channels;
belle_sip_list_t* iterator;
if ((existing_channels=belle_sip_list_size(lp->channels)) > 0) {
belle_sip_warning("Listening point destroying [%i] channels",existing_channels);
}
belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
for (iterator=lp->channels;iterator!=NULL;iterator=iterator->next) {
belle_sip_main_loop_remove_source(lp->stack->ml,(belle_sip_source_t*)(iterator->data));
}
lp->channels=belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
}
......
......@@ -59,11 +59,11 @@ static void belle_sip_authorization_destroy(authorization_context_t* object) {
static void belle_sip_provider_uninit(belle_sip_provider_t *p){
belle_sip_list_free(p->listeners);
belle_sip_list_free(p->internal_listeners);
belle_sip_list_free_with_data(p->lps,belle_sip_object_unref);
belle_sip_list_free_with_data(p->client_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->server_transactions,belle_sip_object_unref);
belle_sip_list_free_with_data(p->auth_contexts,(void(*)(void*))belle_sip_authorization_destroy);
belle_sip_list_free_with_data(p->dialogs,belle_sip_object_unref);
belle_sip_list_free_with_data(p->lps,belle_sip_object_unref);
}
static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_channel_state_t state){
......
......@@ -107,6 +107,7 @@ belle_sip_dialog_t* belle_sip_transaction_get_dialog(const belle_sip_transactio
void belle_sip_transaction_set_dialog(belle_sip_transaction_t *t, belle_sip_dialog_t *dialog){
if (dialog) belle_sip_object_ref(dialog);
if (t->dialog) belle_sip_object_unref(t->dialog); /*to avoid keeping unexpected ref*/
t->dialog=dialog;
}
......
......@@ -64,7 +64,6 @@ void stream_channel_close(belle_sip_channel_t *obj){
belle_sip_fd_t sock = belle_sip_source_get_fd((belle_sip_source_t*)obj);
if (sock!=-1){
close_socket(sock);
belle_sip_main_loop_remove_source(obj->stack->ml,(belle_sip_source_t*)obj);
obj->base.fd=-1;
}
}
......
......@@ -71,6 +71,7 @@ static void check_tls_deinit(void){
}
static void belle_sip_tls_listening_point_uninit(belle_sip_tls_listening_point_t *lp){
belle_sip_listening_point_clean_channels(BELLE_SIP_LISTENING_POINT(lp)); /*make sure all channels are cleaned before deiniting gnu tls*/
check_tls_deinit();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment