Commit 60bd120e authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

libvlc event: Fix the various leaks and point indication on where locking should be done.

parent 78f85ea0
...@@ -813,6 +813,14 @@ VLC_PUBLIC_API void libvlc_event_add_callback( libvlc_instance_t *p_instance, ...@@ -813,6 +813,14 @@ VLC_PUBLIC_API void libvlc_event_add_callback( libvlc_instance_t *p_instance,
void *user_data, void *user_data,
libvlc_exception_t *p_e ); libvlc_exception_t *p_e );
/**
* Unregister all callbacks notification from an instance
* \param p_instance the libvlc instance
* \param p_e an initialized exception pointer
*/
VLC_PUBLIC_API void libvlc_event_remove_all_callbacks( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e );
/** /**
* Unregister a callback notification * Unregister a callback notification
* \param p_instance the libvlc instance * \param p_instance the libvlc instance
......
...@@ -107,15 +107,7 @@ libvlc_instance_t * libvlc_new( int argc, char **argv, ...@@ -107,15 +107,7 @@ libvlc_instance_t * libvlc_new( int argc, char **argv,
void libvlc_destroy( libvlc_instance_t *p_instance, libvlc_exception_t *p_e ) void libvlc_destroy( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
{ {
struct libvlc_callback_entry_list_t *p_listitem = p_instance->p_callback_list; libvlc_event_remove_all_callbacks( p_instance, p_e /* current implementation never triggers it */);
while( p_listitem )
{
struct libvlc_callback_entry_list_t *p_nextlistitem = p_listitem->next;
free( p_listitem );
p_listitem = p_nextlistitem;
}
libvlc_InternalCleanup( p_instance->p_libvlc_int ); libvlc_InternalCleanup( p_instance->p_libvlc_int );
libvlc_InternalDestroy( p_instance->p_libvlc_int, VLC_FALSE ); libvlc_InternalDestroy( p_instance->p_libvlc_int, VLC_FALSE );
} }
......
...@@ -33,7 +33,7 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd, ...@@ -33,7 +33,7 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void *p_data ) void *p_data )
{ {
struct libvlc_callback_entry_t *entry = p_data; struct libvlc_callback_entry_t *entry = p_data; /* FIXME: we need some locking here */
libvlc_event_t event; libvlc_event_t event;
event.type = entry->i_event_type; event.type = entry->i_event_type;
switch ( event.type ) switch ( event.type )
...@@ -63,7 +63,8 @@ static inline void add_callback_entry( struct libvlc_callback_entry_t *entry, ...@@ -63,7 +63,8 @@ static inline void add_callback_entry( struct libvlc_callback_entry_t *entry,
/* malloc/free strategy: /* malloc/free strategy:
* - alloc-ded in add_callback_entry * - alloc-ded in add_callback_entry
* - free-ed by libvlc_event_remove_callback * - free-ed by libvlc_event_remove_callback
* - free-ed in libvlc_destroy when entry is destroyed * - free-ed in libvlc_destroy threw libvlc_event_remove_callback
* when entry is destroyed
*/ */
new_listitem = malloc( sizeof( struct libvlc_callback_entry_list_t ) ); new_listitem = malloc( sizeof( struct libvlc_callback_entry_list_t ) );
new_listitem->elmt = entry; new_listitem->elmt = entry;
...@@ -95,8 +96,9 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance, ...@@ -95,8 +96,9 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance,
/* malloc/free strategy: /* malloc/free strategy:
* - alloc-ded in libvlc_event_add_callback * - alloc-ded in libvlc_event_add_callback
* - free-ed by libvlc_event_add_callback on error * - free-ed by libvlc_event_add_callback on error
* - Not free-ed by libvlc_event_remove_callback (FIXME leaks) * - free-ed by libvlc_event_remove_callback
* - Not free-ed in libvlc_destroy when entry is destroyed (FIXME leaks) * - free-ed in libvlc_destroy threw libvlc_event_remove_callback
* when entry is destroyed
*/ */
entry = malloc( sizeof( struct libvlc_callback_entry_t ) ); entry = malloc( sizeof( struct libvlc_callback_entry_t ) );
entry->f_callback = f_callback; entry->f_callback = f_callback;
...@@ -131,6 +133,23 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance, ...@@ -131,6 +133,23 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance,
return; return;
} }
void libvlc_event_remove_all_callbacks( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{
struct libvlc_callback_entry_list_t *p_listitem = p_instance->p_callback_list;
while( p_listitem )
{
libvlc_event_remove_callback( p_instance,
p_listitem->elmt->i_event_type,
p_listitem->elmt->f_callback,
p_listitem->elmt->p_user_data,
p_e);
/* libvlc_event_remove_callback will reset the p_callback_list */
p_listitem = p_instance->p_callback_list;
}
}
void libvlc_event_remove_callback( libvlc_instance_t *p_instance, void libvlc_event_remove_callback( libvlc_instance_t *p_instance,
libvlc_event_type_t i_event_type, libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback, libvlc_callback_t f_callback,
...@@ -153,6 +172,7 @@ void libvlc_event_remove_callback( libvlc_instance_t *p_instance, ...@@ -153,6 +172,7 @@ void libvlc_event_remove_callback( libvlc_instance_t *p_instance,
p_instance->p_callback_list = p_listitem->next; p_instance->p_callback_list = p_listitem->next;
p_listitem->next->prev = p_listitem->prev; p_listitem->next->prev = p_listitem->prev;
free( p_listitem->elmt ); /* FIXME: need some locking here */
free( p_listitem ); free( p_listitem );
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment