summaryrefslogtreecommitdiff
path: root/res/res_pjsip_outbound_registration.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-01-22 19:14:35 +0000
committerRichard Mudgett <rmudgett@digium.com>2015-01-22 19:14:35 +0000
commite67ca431ee2addffd9e23c895ef170f2dc79bfb6 (patch)
treeda22f2fb93fd5070a87c0f74449ee707d251ca07 /res/res_pjsip_outbound_registration.c
parent49f405fe4c4c758a0d99d05ed2d35f55dd76b732 (diff)
res_pjsip_outbound_registration.c: Minor code cleanup.
* Add an allocation failure check and assert in sip_outbound_registration_response_cb(). * Made sip_outbound_registration_state_destroy() handle partially created state objects from sip_outbound_registration_state_alloc(). Review: https://reviewboard.asterisk.org/r/4366/ ........ Merged revisions 430957 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_outbound_registration.c')
-rw-r--r--res/res_pjsip_outbound_registration.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 2aed231ee..b16ea64b1 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -724,8 +724,14 @@ static int handle_registration_response(void *data)
static void sip_outbound_registration_response_cb(struct pjsip_regc_cbparam *param)
{
RAII_VAR(struct sip_outbound_registration_client_state *, client_state, param->token, ao2_cleanup);
- struct registration_response *response = ao2_alloc(sizeof(*response), registration_response_destroy);
+ struct registration_response *response;
+ ast_assert(client_state != NULL);
+
+ response = ao2_alloc(sizeof(*response), registration_response_destroy);
+ if (!response) {
+ return;
+ }
response->code = param->code;
response->expiration = param->expiration;
response->client_state = client_state;
@@ -753,10 +759,11 @@ static void sip_outbound_registration_state_destroy(void *obj)
ao2_cleanup(state->registration);
if (!state->client_state) {
- return;
- }
-
- if (state->client_state->serializer && ast_sip_push_task(state->client_state->serializer, handle_client_state_destruction, state->client_state)) {
+ /* Nothing to do */
+ } else if (!state->client_state->serializer) {
+ ao2_ref(state->client_state, -1);
+ } else if (ast_sip_push_task(state->client_state->serializer,
+ handle_client_state_destruction, state->client_state)) {
ast_log(LOG_WARNING, "Failed to pass outbound registration client destruction to threadpool\n");
ao2_ref(state->client_state, -1);
}
@@ -773,19 +780,24 @@ static void sip_outbound_registration_client_state_destroy(void *obj)
/*! \brief Allocator function for registration state */
static struct sip_outbound_registration_state *sip_outbound_registration_state_alloc(struct sip_outbound_registration *registration)
{
- struct sip_outbound_registration_state *state = ao2_alloc(sizeof(*state), sip_outbound_registration_state_destroy);
+ struct sip_outbound_registration_state *state;
- if (!state || !(state->client_state = ao2_alloc(sizeof(*state->client_state), sip_outbound_registration_client_state_destroy))) {
+ state = ao2_alloc(sizeof(*state), sip_outbound_registration_state_destroy);
+ if (!state) {
+ return NULL;
+ }
+ state->client_state = ao2_alloc(sizeof(*state->client_state),
+ sip_outbound_registration_client_state_destroy);
+ if (!state->client_state) {
ao2_cleanup(state);
return NULL;
}
- if (!(state->client_state->serializer = ast_sip_create_serializer())) {
- ao2_cleanup(state->client_state);
+ state->client_state->serializer = ast_sip_create_serializer();
+ if (!state->client_state->serializer) {
ao2_cleanup(state);
return NULL;
}
-
state->client_state->status = SIP_REGISTRATION_UNREGISTERED;
state->client_state->timer.user_data = state->client_state;
state->client_state->timer.cb = sip_outbound_registration_timer_cb;
@@ -970,9 +982,10 @@ static int sip_outbound_registration_regc_alloc(void *data)
}
}
- if (!state->client_state->client &&
- pjsip_regc_create(ast_sip_get_pjsip_endpoint(), state->client_state, sip_outbound_registration_response_cb,
- &state->client_state->client) != PJ_SUCCESS) {
+ if (!state->client_state->client
+ && pjsip_regc_create(ast_sip_get_pjsip_endpoint(), state->client_state,
+ sip_outbound_registration_response_cb,
+ &state->client_state->client) != PJ_SUCCESS) {
return -1;
}