Changeset 1421fa57d972c05149470d7f56e4334629c2c8d4

Show
Ignore:
Timestamp:
12/23/07 15:19:00 (9 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1198419540 +0000
git-parent:

[a01893ff324856bc99739e72323eb6616b0b1309]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1198419540 +0000
Message:

vlc_common.h:
* Add some proper assert() to the vlc_gc_* function to spot errors.
* Correctly initialize the refcount to 1. (This will prevent freed pointer usage). (This may also introduce leaks in some module).
modules/*.c:
* Prevent some module to leak input_item_t.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_common.h

    red5205f r1421fa5  
    6464#include <stdlib.h> 
    6565#include <stdarg.h> 
     66#include <assert.h> 
    6667 
    6768#include <string.h> 
     
    611612static inline void __vlc_gc_incref( gc_object_t * p_gc ) 
    612613{ 
     614    assert( p_gc->i_gc_refcount > 0 ); 
     615 
    613616    p_gc->i_gc_refcount ++; 
    614617}; 
     
    616619static inline void __vlc_gc_decref( gc_object_t *p_gc ) 
    617620{ 
     621    if( !p_gc ) return; 
     622 
     623    assert( p_gc->i_gc_refcount > 0 ); 
     624 
    618625    p_gc->i_gc_refcount -- ; 
    619626 
     
    622629        p_gc->pf_destructor( p_gc ); 
    623630        /* Do not use the p_gc pointer from now on ! */ 
    624      } 
     631    } 
     632
     633 
     634static inline void 
     635__vlc_gc_init( gc_object_t * p_gc, void (*pf_destructor)( gc_object_t * ), 
     636               void * arg) 
     637
     638    p_gc->i_gc_refcount = 1; 
     639    p_gc->pf_destructor = pf_destructor; 
     640    p_gc->p_destructor_arg = arg; 
    625641} 
    626642 
    627643#define vlc_gc_incref( a ) __vlc_gc_incref( (gc_object_t *)a ) 
    628644#define vlc_gc_decref( a ) __vlc_gc_decref( (gc_object_t *)a ) 
    629 #define vlc_gc_init( a,b,c ) {  ((gc_object_t *)a)->i_gc_refcount = 0; \ 
    630                               ((gc_object_t *)a)->pf_destructor = b; \ 
    631                               ((gc_object_t *)a)->p_destructor_arg = c; } 
     645#define vlc_gc_init( a,b,c ) __vlc_gc_init( (gc_object_t *)a,b,c ) 
    632646 
    633647 
  • modules/misc/lua/vlc.c

    rc366075 r1421fa5  
    754754                                           PLAYLIST_END, VLC_TRUE, VLC_FALSE ); 
    755755                    i_count ++; /* increment counter */ 
    756  
     756                    vlc_gc_decref( p_input ); 
    757757                    while( i_options > 0 ) 
    758758                        free( ppsz_options[--i_options] ); 
  • modules/services_discovery/bonjour.c

    rc758dd2 r1421fa5  
    190190                name, p_input ); 
    191191            services_discovery_AddItem( p_sd, p_input, NULL /* no category */ ); 
     192            vlc_gc_decref( p_input ); 
    192193       } 
    193194    } 
  • modules/services_discovery/freebox.c

    r3a3b9f8 r1421fa5  
    8989                                _("Freebox TV"), 0, NULL, -1 ); 
    9090    input_ItemAddOption( p_input, "no-playlist-autostart" ); 
    91     vlc_gc_incref( p_input ); 
    9291 
    9392    vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded, ItemAdded, p_sd ); 
  • modules/services_discovery/hal.c

    r0e10f5f r1421fa5  
    202202        return; 
    203203    } 
     204    vlc_gc_incref( p_input ); 
    204205    p_udi_entry->p_item = p_input; 
    205206    p_udi_entry->psz_udi = strdup( psz_device ); 
     
    239240    AddItem( p_sd, p_input ); 
    240241#endif 
     242    vlc_gc_decref( p_input ); 
    241243} 
    242244 
     
    252254        { /* delete the corresponding item */     
    253255            services_discovery_RemoveItem( p_sd, p_sys->pp_devices[i]->p_item ); 
     256            vlc_gc_decref( p_sys->pp_devices[i]->p_item ); 
    254257            if( p_sys->pp_devices[i]->psz_udi ) 
    255258                free( p_sys->pp_devices[i]->psz_udi ); 
     
    285288    AddItem( p_sd, p_input ); 
    286289#endif 
     290    vlc_gc_decref( p_input ); 
    287291} 
    288292 
  • modules/services_discovery/sap.c

    ra8eb03f r1421fa5  
    896896 
    897897    TAB_APPEND( p_sys->i_announces, p_sys->pp_announces, p_sap ); 
    898  
     898    vlc_gc_decref( p_input ); 
    899899    return p_sap; 
    900900} 
  • modules/services_discovery/shout.c

    r74fd4dd r1421fa5  
    140140            break; 
    141141    } 
    142     vlc_gc_incref( p_sys->p_input ); /* Refcount to 1, so we can release it 
    143                                       * in Close() */ 
    144142 
    145143    input_ItemAddOption( p_sys->p_input, "no-playlist-autostart" );