Ignore:
Timestamp:
Nov 21, 2006 12:39:31 PM (17 years ago)
Author:
bennylp
Message:

Fixed handles leak upon program exit, by introducing pj_shutdown() and pj_atexit(). Also fixed handle leaks in SIP transaction layer and SIP endpoint.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/os_core_win32.c

    r746 r815  
    109109 */ 
    110110static pj_thread_desc main_thread; 
    111 static long thread_tls_id; 
     111static long thread_tls_id = -1; 
    112112static pj_mutex_t critical_section_mutex; 
    113  
     113static unsigned atexit_count; 
     114static void (*atexit_func[32])(void); 
    114115 
    115116/* 
     
    178179 
    179180/* 
     181 * pj_atexit() 
     182 */ 
     183PJ_DEF(pj_status_t) pj_atexit(void (*func)(void)) 
     184{ 
     185    if (atexit_count >= PJ_ARRAY_SIZE(atexit_func)) 
     186        return PJ_ETOOMANY; 
     187 
     188    atexit_func[atexit_count++] = func; 
     189    return PJ_SUCCESS; 
     190} 
     191 
     192 
     193/* 
     194 * pj_shutdown(void) 
     195 */ 
     196PJ_DEF(void) pj_shutdown() 
     197{ 
     198    int i; 
     199 
     200    /* Call atexit() functions */ 
     201    for (i=atexit_count-1; i>=0; --i) { 
     202        (*atexit_func[i])(); 
     203    } 
     204    atexit_count = 0; 
     205 
     206    /* Free exception ID */ 
     207    if (PJ_NO_MEMORY_EXCEPTION != -1) { 
     208        pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION); 
     209        PJ_NO_MEMORY_EXCEPTION = -1; 
     210    } 
     211 
     212    /* Destroy PJLIB critical section */ 
     213    pj_mutex_destroy(&critical_section_mutex); 
     214 
     215    /* Free PJLIB TLS */ 
     216    if (thread_tls_id != -1) { 
     217        pj_thread_local_free(thread_tls_id); 
     218        thread_tls_id = -1; 
     219    } 
     220 
     221    /* Shutdown Winsock */ 
     222    WSACleanup(); 
     223} 
     224 
     225 
     226/* 
    180227 * pj_getpid(void) 
    181228 */ 
Note: See TracChangeset for help on using the changeset viewer.