Ignore:
Timestamp:
Jun 7, 2016 10:07:57 AM (8 years ago)
Author:
riza
Message:

Re #1929: Avoid memory pool growing when doing re-Registration.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_auth_client.c

    r5227 r5336  
    358358 * Update authentication session with a challenge. 
    359359 */ 
    360 static void update_digest_session( pj_pool_t *ses_pool, 
    361                                    pjsip_cached_auth *cached_auth, 
     360static void update_digest_session( pjsip_cached_auth *cached_auth, 
    362361                                   const pjsip_www_authenticate_hdr *hdr ) 
    363362{ 
     
    366365        if (!cached_auth->last_chal || pj_stricmp2(&hdr->scheme, "digest")) { 
    367366            cached_auth->last_chal = (pjsip_www_authenticate_hdr*) 
    368                                      pjsip_hdr_clone(ses_pool, hdr); 
     367                                     pjsip_hdr_clone(cached_auth->pool, hdr); 
    369368        } else { 
    370369            /* Only update if the new challenge is "significantly different" 
     
    383382            { 
    384383                cached_auth->last_chal = (pjsip_www_authenticate_hdr*) 
    385                                          pjsip_hdr_clone(ses_pool, hdr); 
     384                                       pjsip_hdr_clone(cached_auth->pool, hdr); 
    386385            } 
    387386        } 
     
    394393        /* Save the whole challenge */ 
    395394        cached_auth->last_chal = (pjsip_www_authenticate_hdr*) 
    396                                  pjsip_hdr_clone(ses_pool, hdr); 
     395                                 pjsip_hdr_clone(cached_auth->pool, hdr); 
    397396 
    398397        /* Create cnonce */ 
    399         pj_create_unique_string( ses_pool, &cached_auth->cnonce ); 
     398        pj_create_unique_string( cached_auth->pool, &cached_auth->cnonce ); 
    400399 
    401400        /* Initialize nonce-count */ 
     
    407406        */ 
    408407        if (cached_auth->realm.slen == 0) { 
    409             pj_strdup(ses_pool, &cached_auth->realm, 
     408            pj_strdup(cached_auth->pool, &cached_auth->realm, 
    410409                      &hdr->challenge.digest.realm); 
    411410        } 
     
    420419        } else { 
    421420            /* Server gives new nonce. */ 
    422             pj_strdup(ses_pool, &cached_auth->last_chal->challenge.digest.nonce, 
     421            pj_strdup(cached_auth->pool,  
     422                      &cached_auth->last_chal->challenge.digest.nonce, 
    423423                      &hdr->challenge.digest.nonce); 
    424424            /* Has the opaque changed? */ 
     
    426426                          &hdr->challenge.digest.opaque)) 
    427427            { 
    428                 pj_strdup(ses_pool, 
     428                pj_strdup(cached_auth->pool, 
    429429                          &cached_auth->last_chal->challenge.digest.opaque, 
    430430                          &hdr->challenge.digest.opaque); 
     
    692692        { 
    693693            if (cached_auth) { 
    694                 update_digest_session( sess_pool, cached_auth, hdr ); 
     694                update_digest_session( cached_auth, hdr ); 
    695695 
    696696                cnonce = &cached_auth->cnonce; 
     
    961961} 
    962962 
     963 
     964static void recreate_cached_auth_pool( pjsip_endpoint *endpt,  
     965                                       pjsip_cached_auth *auth ) 
     966{ 
     967    pj_pool_t *auth_pool = pjsip_endpt_create_pool(endpt, "regc_auth%p", 1024,  
     968                                                   1024); 
     969 
     970    if (auth->realm.slen) { 
     971        pj_str_t realm; 
     972        pj_strdup(auth_pool, &realm, &auth->realm); 
     973        pj_strassign(&auth->realm, &realm); 
     974    } 
     975 
     976    if (auth->cnonce.slen) { 
     977        pj_str_t cnonce; 
     978        pj_strdup(auth_pool, &cnonce, &auth->cnonce); 
     979        pj_strassign(&auth->cnonce, &cnonce); 
     980    } 
     981 
     982    if (auth->last_chal) { 
     983        auth->last_chal = (pjsip_www_authenticate_hdr*) 
     984                          pjsip_hdr_clone(auth_pool, auth->last_chal); 
     985    } 
     986 
     987    pjsip_endpt_release_pool(endpt, auth->pool); 
     988    auth->pool = auth_pool; 
     989} 
    963990 
    964991/* Process authorization challenge */ 
     
    11271154            break; 
    11281155 
    1129         hchal = (const pjsip_www_authenticate_hdr*) hdr; 
     1156        hchal = (const pjsip_www_authenticate_hdr*)hdr; 
    11301157        ++chal_cnt; 
    11311158 
     
    11331160         * if not present. 
    11341161         */ 
    1135         cached_auth = find_cached_auth(sess, &hchal->challenge.common.realm ); 
     1162        cached_auth = find_cached_auth(sess, &hchal->challenge.common.realm); 
    11361163        if (!cached_auth) { 
    1137             cached_auth = PJ_POOL_ZALLOC_T( sess->pool, pjsip_cached_auth); 
    1138             pj_strdup( sess->pool, &cached_auth->realm, &hchal->challenge.common.realm); 
     1164            cached_auth = PJ_POOL_ZALLOC_T(sess->pool, pjsip_cached_auth); 
     1165            cached_auth->pool = pjsip_endpt_create_pool(sess->endpt, 
     1166                                                        "regc_auth%p", 
     1167                                                        1024, 
     1168                                                        1024); 
     1169            pj_strdup(cached_auth->pool, &cached_auth->realm, 
     1170                      &hchal->challenge.common.realm); 
    11391171            cached_auth->is_proxy = (hchal->type == PJSIP_H_PROXY_AUTHENTICATE); 
    11401172#           if (PJSIP_AUTH_HEADER_CACHING) 
     
    11431175            } 
    11441176#           endif 
    1145             pj_list_insert_before( &sess->cached_auth, cached_auth ); 
     1177            pj_list_insert_before(&sess->cached_auth, cached_auth); 
    11461178        } 
    11471179 
     
    11491181         * authorization session. 
    11501182         */ 
    1151         status = process_auth( tdata->pool, hchal, tdata->msg->line.req.uri, 
    1152                                tdata, sess, cached_auth, &hauth); 
     1183        status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri, 
     1184                              tdata, sess, cached_auth, &hauth); 
    11531185        if (status != PJ_SUCCESS) 
    11541186            return status; 
     1187 
     1188        if (pj_pool_get_used_size(cached_auth->pool) > 
     1189            PJSIP_AUTH_CACHED_POOL_MAX_SIZE)  
     1190        { 
     1191            recreate_cached_auth_pool(sess->endpt, cached_auth); 
     1192        }        
    11551193 
    11561194        /* Add to the message. */ 
Note: See TracChangeset for help on using the changeset viewer.