Changeset 0f8d02ae0dade744e73b415326337b772eba2495

Show
Ignore:
Timestamp:
03/03/08 22:29:21 (6 months ago)
Author:
Pierre d'Herbemont <pdherbemont@free.fr>
git-committer:
Pierre d'Herbemont <pdherbemont@free.fr> 1204579761 +0100
git-parent:

[45dc363611bc200a2ee564994690394e26edd914]

git-author:
Pierre d'Herbemont <pdherbemont@free.fr> 1204579761 +0100
Message:

misc/objects.c:
* Fix a rare race condition that may happen because the refcount was changed outside of the structure lock.
* assert(refcount>0) in some key function to help to track freed object easily.
* Use vlc_object_yield_locked() instead of refcount++.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/misc/objects.c

    rfa0e80f r0f8d02a  
    9494 
    9595static void vlc_object_destroy( vlc_object_t *p_this ); 
     96static void vlc_object_yield_locked( vlc_object_t *p_this ); 
    9697 
    9798/***************************************************************************** 
     
    733734                if( pp_objects[i_middle+1]->i_object_id == i_id ) 
    734735                { 
     736                    vlc_object_yield_locked( pp_objects[i_middle+1] ); 
    735737                    vlc_mutex_unlock( &structure_lock ); 
    736                     pp_objects[i_middle+1]->p_internals->i_refcount++; 
    737738                    return pp_objects[i_middle+1]; 
    738739                } 
     
    742743        else 
    743744        { 
     745            vlc_object_yield_locked( pp_objects[i_middle] ); 
    744746            vlc_mutex_unlock( &structure_lock ); 
    745             pp_objects[i_middle]->p_internals->i_refcount++; 
    746747            return pp_objects[i_middle]; 
    747748        } 
     
    772773    vlc_mutex_lock( &structure_lock ); 
    773774 
     775    /* Avoid obvious freed object uses */ 
     776    assert( p_this->p_internals->i_refcount > 0 ); 
     777 
    774778    /* If we are of the requested type ourselves, don't look further */ 
    775779    if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type ) 
    776780    { 
    777         p_this->p_internals->i_refcount++
     781        vlc_object_yield_locked( p_this )
    778782        vlc_mutex_unlock( &structure_lock ); 
    779783        return p_this; 
     
    823827    vlc_mutex_lock( &structure_lock ); 
    824828 
     829    /* Avoid obvious freed object uses */ 
     830    assert( p_this->p_internals->i_refcount > 0 ); 
     831 
    825832    /* If have the requested name ourselves, don't look further */ 
    826833    if( !(i_mode & FIND_STRICT) 
     
    828835        && !strcmp( p_this->psz_object_name, psz_name ) ) 
    829836    { 
    830         p_this->p_internals->i_refcount++
     837        vlc_object_yield_locked( p_this )
    831838        vlc_mutex_unlock( &structure_lock ); 
    832839        return p_this; 
     
    867874 * increment an object refcount 
    868875 *****************************************************************************/ 
     876 
     877/* When the structure_lock is locked */ 
     878static void vlc_object_yield_locked( vlc_object_t *p_this ) 
     879{ 
     880    /* Avoid obvious freed object uses */ 
     881    assert( p_this->p_internals->i_refcount > 0 ); 
     882 
     883    /* Increment the counter */ 
     884    p_this->p_internals->i_refcount++; 
     885} 
     886 
     887/* Public function */ 
    869888void __vlc_object_yield( vlc_object_t *p_this ) 
    870889{ 
    871890    vlc_mutex_lock( &structure_lock ); 
    872     p_this->p_internals->i_refcount++
     891    vlc_object_yield_locked( p_this )
    873892    vlc_mutex_unlock( &structure_lock ); 
    874893} 
     894 
    875895 
    876896/***************************************************************************** 
     
    922942    vlc_mutex_lock( &structure_lock ); 
    923943 
     944    /* Avoid obvious freed object uses */ 
     945    assert( p_this->p_internals->i_refcount > 0 ); 
     946 
    924947    /* Attach the parent to its child */ 
    925948    p_this->p_parent = p_parent; 
     
    949972 
    950973    vlc_mutex_lock( &structure_lock ); 
     974 
     975    /* Avoid obvious freed object uses */ 
     976    assert( p_this->p_internals->i_refcount > 0 ); 
     977 
    951978    if( !p_this->p_parent ) 
    952979    { 
     
    9821009 
    9831010    vlc_mutex_lock( &structure_lock ); 
     1011 
     1012    /* Avoid obvious freed object uses */ 
     1013    assert( p_this->p_internals->i_refcount > 0 ); 
    9841014 
    9851015    /* Look for the objects */ 
     
    12911321            if( p_tmp->i_object_type == i_type ) 
    12921322            { 
    1293                 p_tmp->p_internals->i_refcount++
     1323                vlc_object_yield_locked( p_tmp )
    12941324                return p_tmp; 
    12951325            } 
     
    13071337            if( p_tmp->i_object_type == i_type ) 
    13081338            { 
    1309                 p_tmp->p_internals->i_refcount++
     1339                vlc_object_yield_locked( p_tmp )
    13101340                return p_tmp; 
    13111341            } 
     
    13451375                && !strcmp( p_tmp->psz_object_name, psz_name ) ) 
    13461376            { 
    1347                 p_tmp->p_internals->i_refcount++
     1377                vlc_object_yield_locked( p_tmp )
    13481378                return p_tmp; 
    13491379            } 
     
    13621392                && !strcmp( p_tmp->psz_object_name, psz_name ) ) 
    13631393            { 
    1364                 p_tmp->p_internals->i_refcount++
     1394                vlc_object_yield_locked( p_tmp )
    13651395                return p_tmp; 
    13661396            } 
     
    15631593    } 
    15641594 
    1565     p_object->p_internals->i_refcount++
     1595    vlc_object_yield_locked( p_object )
    15661596 
    15671597    p_list->p_values[i_index].p_object = p_object; 
     
    15851615    } 
    15861616 
    1587     p_object->p_internals->i_refcount++
     1617    vlc_object_yield_locked( p_object )
    15881618 
    15891619    p_list->p_values[p_list->i_count].p_object = p_object;