[vlc-devel] commit: sap: Properly manage object memory. (Pierre d'Herbemont )

git version control git at videolan.org
Wed Mar 26 23:58:00 CET 2008


vlc | branch: master | Pierre d'Herbemont <pdherbemont at videolan.org> | Wed Mar 26 23:56:18 2008 +0100| [85dfdfdde360f9a5de9ab8243123cfdd83efd5c1]

sap: Properly manage object memory.

Use an vlc_object_t destructor.
Don't use free, instead of vlc_object_release().

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=85dfdfdde360f9a5de9ab8243123cfdd83efd5c1
---

 src/stream_output/announce.c      |    6 ++----
 src/stream_output/sap.c           |   23 ++++++++++-------------
 src/stream_output/stream_output.h |    2 +-
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/src/stream_output/announce.c b/src/stream_output/announce.c
index c1bb2da..a8b383b 100644
--- a/src/stream_output/announce.c
+++ b/src/stream_output/announce.c
@@ -180,10 +180,8 @@ int announce_HandlerDestroy( announce_handler_t *p_announce )
 {
     if( p_announce->p_sap )
     {
-        vlc_object_kill ((vlc_object_t *)p_announce->p_sap);
-        /* Wait for the SAP thread to exit */
-        vlc_thread_join( (vlc_object_t *)p_announce->p_sap );
-        announce_SAPHandlerDestroy( p_announce->p_sap );
+        /* Exit the SAP */
+        vlc_object_release( p_announce->p_sap );
     }
 
     /* Free the structure */
diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c
index c0caf43..c234ee8 100644
--- a/src/stream_output/sap.c
+++ b/src/stream_output/sap.c
@@ -106,6 +106,8 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
 static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
                              session_descriptor_t *p_session );
 
+static void announce_SAPHandlerDestructor( vlc_object_t *p_this );
+
 
 /**
  * Create the SAP handler
@@ -140,24 +142,22 @@ sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
                        VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
     {
         msg_Dbg( p_announce, "unable to spawn SAP handler thread");
-        free( p_sap );
+        vlc_object_release( p_sap );
         return NULL;
-    };
+    }
+
+    vlc_object_set_destructor( p_sap, announce_SAPHandlerDestructor );
+
     msg_Dbg( p_announce, "thread created, %i sessions", p_sap->i_sessions);
+
     return p_sap;
 }
 
-/**
- *  Destroy the SAP handler
- *  \param p_this the SAP Handler to destroy
- *  \return nothing
- */
-void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
+static void announce_SAPHandlerDestructor( vlc_object_t * p_this )
 {
+    sap_handler_t *p_sap = (sap_handler_t *)p_this;
     int i;
 
-    vlc_mutex_destroy( &p_sap->object_lock );
-
     /* Free the remaining sessions */
     for( i = 0 ; i< p_sap->i_sessions ; i++)
     {
@@ -183,9 +183,6 @@ void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
         REMOVE_ELEM( p_sap->pp_addresses, p_sap->i_addresses, i );
         FREENULL( p_address );
     }
-
-    /* Free the structure */
-    vlc_object_release( p_sap );
 }
 
 /**
diff --git a/src/stream_output/stream_output.h b/src/stream_output/stream_output.h
index 723f628..073de80 100644
--- a/src/stream_output/stream_output.h
+++ b/src/stream_output/stream_output.h
@@ -98,7 +98,7 @@ struct announce_handler_t
 
 int announce_HandlerDestroy( announce_handler_t * );
 
+/* Release it with vlc_object_release() */
 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce );
-void announce_SAPHandlerDestroy( sap_handler_t *p_sap );
 
 #endif




More information about the vlc-devel mailing list