Changeset 0f8d02ae0dade744e73b415326337b772eba2495
- 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
| rfa0e80f |
r0f8d02a |
|
| 94 | 94 | |
|---|
| 95 | 95 | static void vlc_object_destroy( vlc_object_t *p_this ); |
|---|
| | 96 | static void vlc_object_yield_locked( vlc_object_t *p_this ); |
|---|
| 96 | 97 | |
|---|
| 97 | 98 | /***************************************************************************** |
|---|
| … | … | |
| 733 | 734 | if( pp_objects[i_middle+1]->i_object_id == i_id ) |
|---|
| 734 | 735 | { |
|---|
| | 736 | vlc_object_yield_locked( pp_objects[i_middle+1] ); |
|---|
| 735 | 737 | vlc_mutex_unlock( &structure_lock ); |
|---|
| 736 | | pp_objects[i_middle+1]->p_internals->i_refcount++; |
|---|
| 737 | 738 | return pp_objects[i_middle+1]; |
|---|
| 738 | 739 | } |
|---|
| … | … | |
| 742 | 743 | else |
|---|
| 743 | 744 | { |
|---|
| | 745 | vlc_object_yield_locked( pp_objects[i_middle] ); |
|---|
| 744 | 746 | vlc_mutex_unlock( &structure_lock ); |
|---|
| 745 | | pp_objects[i_middle]->p_internals->i_refcount++; |
|---|
| 746 | 747 | return pp_objects[i_middle]; |
|---|
| 747 | 748 | } |
|---|
| … | … | |
| 772 | 773 | vlc_mutex_lock( &structure_lock ); |
|---|
| 773 | 774 | |
|---|
| | 775 | /* Avoid obvious freed object uses */ |
|---|
| | 776 | assert( p_this->p_internals->i_refcount > 0 ); |
|---|
| | 777 | |
|---|
| 774 | 778 | /* If we are of the requested type ourselves, don't look further */ |
|---|
| 775 | 779 | if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type ) |
|---|
| 776 | 780 | { |
|---|
| 777 | | p_this->p_internals->i_refcount++; |
|---|
| | 781 | vlc_object_yield_locked( p_this ); |
|---|
| 778 | 782 | vlc_mutex_unlock( &structure_lock ); |
|---|
| 779 | 783 | return p_this; |
|---|
| … | … | |
| 823 | 827 | vlc_mutex_lock( &structure_lock ); |
|---|
| 824 | 828 | |
|---|
| | 829 | /* Avoid obvious freed object uses */ |
|---|
| | 830 | assert( p_this->p_internals->i_refcount > 0 ); |
|---|
| | 831 | |
|---|
| 825 | 832 | /* If have the requested name ourselves, don't look further */ |
|---|
| 826 | 833 | if( !(i_mode & FIND_STRICT) |
|---|
| … | … | |
| 828 | 835 | && !strcmp( p_this->psz_object_name, psz_name ) ) |
|---|
| 829 | 836 | { |
|---|
| 830 | | p_this->p_internals->i_refcount++; |
|---|
| | 837 | vlc_object_yield_locked( p_this ); |
|---|
| 831 | 838 | vlc_mutex_unlock( &structure_lock ); |
|---|
| 832 | 839 | return p_this; |
|---|
| … | … | |
| 867 | 874 | * increment an object refcount |
|---|
| 868 | 875 | *****************************************************************************/ |
|---|
| | 876 | |
|---|
| | 877 | /* When the structure_lock is locked */ |
|---|
| | 878 | static 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 */ |
|---|
| 869 | 888 | void __vlc_object_yield( vlc_object_t *p_this ) |
|---|
| 870 | 889 | { |
|---|
| 871 | 890 | vlc_mutex_lock( &structure_lock ); |
|---|
| 872 | | p_this->p_internals->i_refcount++; |
|---|
| | 891 | vlc_object_yield_locked( p_this ); |
|---|
| 873 | 892 | vlc_mutex_unlock( &structure_lock ); |
|---|
| 874 | 893 | } |
|---|
| | 894 | |
|---|
| 875 | 895 | |
|---|
| 876 | 896 | /***************************************************************************** |
|---|
| … | … | |
| 922 | 942 | vlc_mutex_lock( &structure_lock ); |
|---|
| 923 | 943 | |
|---|
| | 944 | /* Avoid obvious freed object uses */ |
|---|
| | 945 | assert( p_this->p_internals->i_refcount > 0 ); |
|---|
| | 946 | |
|---|
| 924 | 947 | /* Attach the parent to its child */ |
|---|
| 925 | 948 | p_this->p_parent = p_parent; |
|---|
| … | … | |
| 949 | 972 | |
|---|
| 950 | 973 | vlc_mutex_lock( &structure_lock ); |
|---|
| | 974 | |
|---|
| | 975 | /* Avoid obvious freed object uses */ |
|---|
| | 976 | assert( p_this->p_internals->i_refcount > 0 ); |
|---|
| | 977 | |
|---|
| 951 | 978 | if( !p_this->p_parent ) |
|---|
| 952 | 979 | { |
|---|
| … | … | |
| 982 | 1009 | |
|---|
| 983 | 1010 | vlc_mutex_lock( &structure_lock ); |
|---|
| | 1011 | |
|---|
| | 1012 | /* Avoid obvious freed object uses */ |
|---|
| | 1013 | assert( p_this->p_internals->i_refcount > 0 ); |
|---|
| 984 | 1014 | |
|---|
| 985 | 1015 | /* Look for the objects */ |
|---|
| … | … | |
| 1291 | 1321 | if( p_tmp->i_object_type == i_type ) |
|---|
| 1292 | 1322 | { |
|---|
| 1293 | | p_tmp->p_internals->i_refcount++; |
|---|
| | 1323 | vlc_object_yield_locked( p_tmp ); |
|---|
| 1294 | 1324 | return p_tmp; |
|---|
| 1295 | 1325 | } |
|---|
| … | … | |
| 1307 | 1337 | if( p_tmp->i_object_type == i_type ) |
|---|
| 1308 | 1338 | { |
|---|
| 1309 | | p_tmp->p_internals->i_refcount++; |
|---|
| | 1339 | vlc_object_yield_locked( p_tmp ); |
|---|
| 1310 | 1340 | return p_tmp; |
|---|
| 1311 | 1341 | } |
|---|
| … | … | |
| 1345 | 1375 | && !strcmp( p_tmp->psz_object_name, psz_name ) ) |
|---|
| 1346 | 1376 | { |
|---|
| 1347 | | p_tmp->p_internals->i_refcount++; |
|---|
| | 1377 | vlc_object_yield_locked( p_tmp ); |
|---|
| 1348 | 1378 | return p_tmp; |
|---|
| 1349 | 1379 | } |
|---|
| … | … | |
| 1362 | 1392 | && !strcmp( p_tmp->psz_object_name, psz_name ) ) |
|---|
| 1363 | 1393 | { |
|---|
| 1364 | | p_tmp->p_internals->i_refcount++; |
|---|
| | 1394 | vlc_object_yield_locked( p_tmp ); |
|---|
| 1365 | 1395 | return p_tmp; |
|---|
| 1366 | 1396 | } |
|---|
| … | … | |
| 1563 | 1593 | } |
|---|
| 1564 | 1594 | |
|---|
| 1565 | | p_object->p_internals->i_refcount++; |
|---|
| | 1595 | vlc_object_yield_locked( p_object ); |
|---|
| 1566 | 1596 | |
|---|
| 1567 | 1597 | p_list->p_values[i_index].p_object = p_object; |
|---|
| … | … | |
| 1585 | 1615 | } |
|---|
| 1586 | 1616 | |
|---|
| 1587 | | p_object->p_internals->i_refcount++; |
|---|
| | 1617 | vlc_object_yield_locked( p_object ); |
|---|
| 1588 | 1618 | |
|---|
| 1589 | 1619 | p_list->p_values[p_list->i_count].p_object = p_object; |
|---|