Ignore:
Timestamp:
Dec 2, 2007, 4:35:44 PM (13 years ago)
Author:
charles
Message:

possible fix for the crash reported by sedatg in ticket #519

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r4001 r4040  
    3939  #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_PROFILE */
    4040#else
     41  #define _XOPEN_SOURCE 500 /* needed for recursive locks. */
    4142  #include <pthread.h>
    4243#endif
     
    190191struct tr_lock
    191192{
    192     uint32_t depth;
     193    int depth;
    193194#ifdef __BEOS__
    194195    sem_id lock;
     
    211212    l->lock = create_sem( 1, "" );
    212213#elif defined(WIN32)
    213     InitializeCriticalSection( &l->lock );
    214 #else
    215     pthread_mutex_init( &l->lock, NULL );
     214    InitializeCriticalSection( &l->lock ); /* critical sections support recursion */
     215#else
     216    pthread_mutexattr_t attr;
     217    pthread_mutexattr_init( &attr );
     218    pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
     219    pthread_mutex_init( &l->lock, &attr );
    216220#endif
    217221
     
    237241    const tr_thread_id currentThread = tr_getCurrentThread( );
    238242
    239     if( l->lockThread == currentThread )
    240     {
    241         ++l->depth;
    242     }
    243     else
    244     {
    245 #ifdef __BEOS__
    246         acquire_sem( l->lock );
    247 #elif defined(WIN32)
    248         EnterCriticalSection( &l->lock );
    249 #else
    250         pthread_mutex_lock( &l->lock );
    251 #endif
    252         l->lockThread = currentThread;
    253         l->depth = 1;
    254     }
     243#ifdef __BEOS__
     244    acquire_sem( l->lock );
     245#elif defined(WIN32)
     246    EnterCriticalSection( &l->lock );
     247#else
     248    pthread_mutex_lock( &l->lock );
     249#endif
     250    l->lockThread = currentThread;
     251    ++l->depth;
    255252}
    256253
     
    267264    assert( tr_lockHave( l ) );
    268265
    269     if( !--l->depth )
    270     {
    271         l->lockThread = 0;
    272 #ifdef __BEOS__
    273         release_sem( l->lock );
    274 #elif defined(WIN32)
    275         LeaveCriticalSection( &l->lock );
    276 #else
    277         pthread_mutex_unlock( &l->lock );
    278 #endif
    279     }
     266#ifdef __BEOS__
     267    release_sem( l->lock );
     268#elif defined(WIN32)
     269    LeaveCriticalSection( &l->lock );
     270#else
     271    pthread_mutex_unlock( &l->lock );
     272#endif
     273    --l->depth;
    280274}
    281275
     
    852846    }
    853847
    854     bzero( &snl, sizeof( snl ) );
     848    memset( &snl, 0, sizeof(snl) );
    855849    snl.nl_family = AF_NETLINK;
    856850
    857     bzero( &req, sizeof( req ) );
     851    memset( &req, 0, sizeof(req) );
    858852    req.nlh.nlmsg_len = NLMSG_LENGTH( sizeof( req.rtg ) );
    859853    req.nlh.nlmsg_type = RTM_GETROUTE;
     
    893887    for( ;; )
    894888    {
    895         bzero( &snl, sizeof( snl ) );
    896889        slen = sizeof( snl );
     890        memset( &snl, 0, slen );
    897891        res = recvfrom( fd, buf, len, 0, (struct sockaddr *) &snl, &slen );
    898892        if( 0 > res )
Note: See TracChangeset for help on using the changeset viewer.