]> git.sesse.net Git - vlc/blobdiff - modules/control/telnet.c
Fix a memleak when a connection is closed.
[vlc] / modules / control / telnet.c
index 6a10b0b3ad5ccf09b8894b94c070ec70a5fe8e64..4efdfc9b43012bdfbd2c083befecad4ac34f876a 100644 (file)
@@ -30,7 +30,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_input.h>
 
@@ -93,13 +94,13 @@ vlc_module_begin();
     set_category( CAT_INTERFACE );
     set_subcategory( SUBCAT_INTERFACE_CONTROL );
     add_string( "telnet-host", "", NULL, TELNETHOST_TEXT,
-                 TELNETHOST_LONGTEXT, VLC_TRUE );
+                 TELNETHOST_LONGTEXT, true );
     add_integer( "telnet-port", TELNETPORT_DEFAULT, NULL, TELNETPORT_TEXT,
-                 TELNETPORT_LONGTEXT, VLC_TRUE );
+                 TELNETPORT_LONGTEXT, true );
     add_password( "telnet-password", TELNETPWD_DEFAULT, NULL, TELNETPWD_TEXT,
-                TELNETPWD_LONGTEXT, VLC_TRUE );
-    set_description( _("VLM remote control interface") );
-    add_category_hint( "VLM", NULL, VLC_FALSE );
+                TELNETPWD_LONGTEXT, true );
+    set_description( N_("VLM remote control interface") );
+    add_category_hint( "VLM", NULL, false );
     set_capability( "interface", 0 );
     set_callbacks( Open , Close );
 vlc_module_end();
@@ -185,18 +186,24 @@ static int Open( vlc_object_t *p_this )
     psz_address  = config_GetPsz( p_intf, "telnet-host" );
 
     vlc_UrlParse(&url, psz_address, 0);
+    free( psz_address );
 
     // There might be two ports given, resolve any potentially
     // conflict
     url.i_port = getPort(p_intf, url, i_telnetport);
 
     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
-    if( ( p_intf->p_sys->pi_fd = net_ListenTCP( p_intf, url.psz_host, url.i_port ) )
-                == NULL )
+    if( !p_intf->p_sys )
+    {
+        vlm_Delete( p_intf->p_sys->mediatheque );
+        vlc_UrlClean( &url );
+        return VLC_ENOMEM;
+    }
+    if( ( p_intf->p_sys->pi_fd = net_ListenTCP( p_intf, url.psz_host, url.i_port ) ) == NULL )
     {
         msg_Err( p_intf, "cannot listen for telnet" );
-        vlc_UrlClean(&url);
-        free( psz_address );
+        vlm_Delete( p_intf->p_sys->mediatheque );
+        vlc_UrlClean( &url );
         free( p_intf->p_sys );
         return VLC_EGENERIC;
     }
@@ -209,8 +216,7 @@ static int Open( vlc_object_t *p_this )
     p_intf->p_sys->mediatheque = mediatheque;
     p_intf->pf_run = Run;
 
-    vlc_UrlClean(&url);
-    free( psz_address );
+    vlc_UrlClean( &url );
     return VLC_SUCCESS;
 }
 
@@ -227,10 +233,10 @@ static void Close( vlc_object_t *p_this )
     {
         telnet_client_t *cl = p_sys->clients[i];
         net_Close( cl->fd );
+        free( cl->buffer_write );
         free( cl );
-        p_sys->clients[i] = NULL;
     }
-    if( p_sys->clients != NULL ) free( p_sys->clients );
+    free( p_sys->clients );
 
     net_ListenClose( p_sys->pi_fd );
 
@@ -418,6 +424,7 @@ static void Run( intf_thread_t *p_intf )
                     net_Close( cl->fd );
                     TAB_REMOVE( p_intf->p_sys->i_clients ,
                                 p_intf->p_sys->clients , cl );
+                    free( cl->buffer_write );
                     free( cl );
                 }
                 else if( !strncmp( cl->buffer_read, "shutdown", 8 ) )
@@ -481,7 +488,6 @@ static void Run( intf_thread_t *p_intf )
                     }
                     Write_message( cl, message, NULL, WRITE_MODE_CMD );
                     vlm_MessageDelete( message );
-
                 }
             }
         }
@@ -515,8 +521,7 @@ static void Run( intf_thread_t *p_intf )
             TAB_APPEND( p_sys->i_clients, p_sys->clients, cl );
         }
     }
-    if( psz_password )
-        free( psz_password );
+    free( psz_password );
 }
 
 static void Write_message( telnet_client_t *client, vlm_message_t *message,
@@ -526,7 +531,7 @@ static void Write_message( telnet_client_t *client, vlm_message_t *message,
 
     client->p_buffer_read = client->buffer_read;
     (client->p_buffer_read)[0] = 0; // if (cl->p_buffer_read)[0] = '\n'
-    if( client->buffer_write ) free( client->buffer_write );
+    free( client->buffer_write );
 
     /* generate the psz_message string */
     if( message )