Commit 962a9863 authored by Simon Morlat's avatar Simon Morlat

fix crash due to missing weak_unref.

parent 8e7e210a
......@@ -623,6 +623,7 @@ struct belle_http_request{
};
void belle_http_request_set_listener(belle_http_request_t *req, belle_http_request_listener_t *l);
void belle_http_request_set_channel(belle_http_request_t *req, belle_sip_channel_t *chan);
void belle_http_request_set_response(belle_http_request_t *req, belle_http_response_t *resp);
/*
belle_sip_transaction_t
......
......@@ -32,6 +32,7 @@ static void belle_http_request_destroy(belle_http_request_t *req){
if (req->req_uri) belle_sip_object_unref(req->req_uri);
DESTROY_STRING(req,method)
belle_http_request_set_listener(req,NULL);
belle_http_request_set_channel(req,NULL);
SET_OBJECT_PROPERTY(req,orig_uri,NULL);
SET_OBJECT_PROPERTY(req,response,NULL);
}
......@@ -94,6 +95,21 @@ void belle_http_request_set_listener(belle_http_request_t *req, belle_http_reque
}
}
static void notify_http_request_of_channel_destruction(belle_http_request_t *obj, belle_sip_channel_t *chan_being_destroyed){
obj->channel=NULL;
}
void belle_http_request_set_channel(belle_http_request_t *req, belle_sip_channel_t* chan){
if (req->channel){
belle_sip_object_weak_unref(req->channel, (belle_sip_object_destroy_notify_t)notify_http_request_of_channel_destruction, req);
req->channel=NULL;
}
if (chan){
belle_sip_object_weak_ref(chan, (belle_sip_object_destroy_notify_t)notify_http_request_of_channel_destruction, req);
req->channel=chan;
}
}
belle_http_request_listener_t * belle_http_request_get_listener(const belle_http_request_t *req){
return req->listener;
}
......
......@@ -382,10 +382,6 @@ static void belle_http_end_background_task(void* data) {
}
}
static void notify_http_request_of_channel_destruction(belle_http_request_t *obj, belle_sip_channel_t *chan_being_destroyed){
obj->channel=NULL;
}
int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){
belle_sip_channel_t *chan;
belle_sip_hop_t *hop=belle_sip_hop_new_from_generic_uri(req->orig_uri ? req->orig_uri : req->req_uri);
......@@ -416,8 +412,7 @@ int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_requ
split_request_url(req);
fix_request(req);
belle_sip_object_weak_ref(chan, (belle_sip_object_destroy_notify_t)notify_http_request_of_channel_destruction, req);
req->channel=chan;
belle_http_request_set_channel(req,chan);
if( req->background_task_id != 0){
req->background_task_id = belle_sip_begin_background_task("belle-sip http", belle_http_end_background_task, req);
}
......
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