Changeset 1421fa57d972c05149470d7f56e4334629c2c8d4
- 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
| red5205f |
r1421fa5 |
|
| 64 | 64 | #include <stdlib.h> |
|---|
| 65 | 65 | #include <stdarg.h> |
|---|
| | 66 | #include <assert.h> |
|---|
| 66 | 67 | |
|---|
| 67 | 68 | #include <string.h> |
|---|
| … | … | |
| 611 | 612 | static inline void __vlc_gc_incref( gc_object_t * p_gc ) |
|---|
| 612 | 613 | { |
|---|
| | 614 | assert( p_gc->i_gc_refcount > 0 ); |
|---|
| | 615 | |
|---|
| 613 | 616 | p_gc->i_gc_refcount ++; |
|---|
| 614 | 617 | }; |
|---|
| … | … | |
| 616 | 619 | static inline void __vlc_gc_decref( gc_object_t *p_gc ) |
|---|
| 617 | 620 | { |
|---|
| | 621 | if( !p_gc ) return; |
|---|
| | 622 | |
|---|
| | 623 | assert( p_gc->i_gc_refcount > 0 ); |
|---|
| | 624 | |
|---|
| 618 | 625 | p_gc->i_gc_refcount -- ; |
|---|
| 619 | 626 | |
|---|
| … | … | |
| 622 | 629 | p_gc->pf_destructor( p_gc ); |
|---|
| 623 | 630 | /* Do not use the p_gc pointer from now on ! */ |
|---|
| 624 | | } |
|---|
| | 631 | } |
|---|
| | 632 | } |
|---|
| | 633 | |
|---|
| | 634 | static 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; |
|---|
| 625 | 641 | } |
|---|
| 626 | 642 | |
|---|
| 627 | 643 | #define vlc_gc_incref( a ) __vlc_gc_incref( (gc_object_t *)a ) |
|---|
| 628 | 644 | #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 ) |
|---|
| 632 | 646 | |
|---|
| 633 | 647 | |
|---|
| rc366075 |
r1421fa5 |
|
| 754 | 754 | PLAYLIST_END, VLC_TRUE, VLC_FALSE ); |
|---|
| 755 | 755 | i_count ++; /* increment counter */ |
|---|
| 756 | | |
|---|
| | 756 | vlc_gc_decref( p_input ); |
|---|
| 757 | 757 | while( i_options > 0 ) |
|---|
| 758 | 758 | free( ppsz_options[--i_options] ); |
|---|
| rc758dd2 |
r1421fa5 |
|
| 190 | 190 | name, p_input ); |
|---|
| 191 | 191 | services_discovery_AddItem( p_sd, p_input, NULL /* no category */ ); |
|---|
| | 192 | vlc_gc_decref( p_input ); |
|---|
| 192 | 193 | } |
|---|
| 193 | 194 | } |
|---|
| r3a3b9f8 |
r1421fa5 |
|
| 89 | 89 | _("Freebox TV"), 0, NULL, -1 ); |
|---|
| 90 | 90 | input_ItemAddOption( p_input, "no-playlist-autostart" ); |
|---|
| 91 | | vlc_gc_incref( p_input ); |
|---|
| 92 | 91 | |
|---|
| 93 | 92 | vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded, ItemAdded, p_sd ); |
|---|
| r0e10f5f |
r1421fa5 |
|
| 202 | 202 | return; |
|---|
| 203 | 203 | } |
|---|
| | 204 | vlc_gc_incref( p_input ); |
|---|
| 204 | 205 | p_udi_entry->p_item = p_input; |
|---|
| 205 | 206 | p_udi_entry->psz_udi = strdup( psz_device ); |
|---|
| … | … | |
| 239 | 240 | AddItem( p_sd, p_input ); |
|---|
| 240 | 241 | #endif |
|---|
| | 242 | vlc_gc_decref( p_input ); |
|---|
| 241 | 243 | } |
|---|
| 242 | 244 | |
|---|
| … | … | |
| 252 | 254 | { /* delete the corresponding item */ |
|---|
| 253 | 255 | services_discovery_RemoveItem( p_sd, p_sys->pp_devices[i]->p_item ); |
|---|
| | 256 | vlc_gc_decref( p_sys->pp_devices[i]->p_item ); |
|---|
| 254 | 257 | if( p_sys->pp_devices[i]->psz_udi ) |
|---|
| 255 | 258 | free( p_sys->pp_devices[i]->psz_udi ); |
|---|
| … | … | |
| 285 | 288 | AddItem( p_sd, p_input ); |
|---|
| 286 | 289 | #endif |
|---|
| | 290 | vlc_gc_decref( p_input ); |
|---|
| 287 | 291 | } |
|---|
| 288 | 292 | |
|---|
| ra8eb03f |
r1421fa5 |
|
| 896 | 896 | |
|---|
| 897 | 897 | TAB_APPEND( p_sys->i_announces, p_sys->pp_announces, p_sap ); |
|---|
| 898 | | |
|---|
| | 898 | vlc_gc_decref( p_input ); |
|---|
| 899 | 899 | return p_sap; |
|---|
| 900 | 900 | } |
|---|
| r74fd4dd |
r1421fa5 |
|
| 140 | 140 | break; |
|---|
| 141 | 141 | } |
|---|
| 142 | | vlc_gc_incref( p_sys->p_input ); /* Refcount to 1, so we can release it |
|---|
| 143 | | * in Close() */ |
|---|
| 144 | 142 | |
|---|
| 145 | 143 | input_ItemAddOption( p_sys->p_input, "no-playlist-autostart" ); |
|---|