]> git.sesse.net Git - vlc/commitdiff
* modules/control/http.c: fixed buffer allocation problem.
authorGildas Bazin <gbazin@videolan.org>
Sun, 27 Apr 2003 00:02:27 +0000 (00:02 +0000)
committerGildas Bazin <gbazin@videolan.org>
Sun, 27 Apr 2003 00:02:27 +0000 (00:02 +0000)
modules/control/http.c

index be7df339404e8160076d4880e6e35f96db1d55c9..ed90ed17f6ea757320bd7114702eb1d1e5f44c5e 100644 (file)
@@ -2,7 +2,7 @@
  * http.c :  http remote control plugin for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: http.c,v 1.1 2003/04/26 21:36:23 gbazin Exp $
+ * $Id: http.c,v 1.2 2003/04/27 00:02:27 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -368,10 +368,23 @@ static int httpd_page_interface_update( intf_thread_t *p_intf,
                                         playlist_t *p_playlist,
                                         uint8_t **pp_data, int *pi_data )
 {
-    int i;
+    int i, i_size = 0;
     char *p;
 
-    p = *pp_data = malloc( 10240 );
+    vlc_mutex_lock( &p_playlist->object_lock );
+
+    /*
+     * Count playlist items for memory allocation
+     */
+    for ( i = 0; i < p_playlist->i_size; i++ )
+    {
+        i_size += sizeof("<a href=?action=play&item=?>? - </a><br />\n" );
+        i_size += strlen( p_playlist->pp_items[i]->psz_name );
+    }
+    /* add something for all the static strings below */
+    i_size += 8192;
+
+    p = *pp_data = malloc( i_size );
 
     p += sprintf( p, "<html>\n" );
     p += sprintf( p, "<head>\n" );
@@ -427,5 +440,7 @@ static int httpd_page_interface_update( intf_thread_t *p_intf,
 
     *pi_data = strlen( *pp_data ) + 1;
 
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
     return VLC_SUCCESS;
 }