[MPlayer-cvslog] r33014 - in trunk/gui: app.c app.h interface.c

ib subversion at mplayerhq.hu
Thu Mar 3 14:45:31 CET 2011


Author: ib
Date: Thu Mar  3 14:45:30 2011
New Revision: 33014

Log:
Fix memory leak in appInitStruct().

The NumberOf{Main,Bar,Menu}Items members actually don't hold the
number of items but the last index used. Therefore, the last item
won't get freed so far.

To set the correct "number" for the global external variable prior
to using it, the function appResetStruct() has been added and is used
in appInitStruct() as well.

Modified:
   trunk/gui/app.c
   trunk/gui/app.h
   trunk/gui/interface.c

Modified: trunk/gui/app.c
==============================================================================
--- trunk/gui/app.c	Thu Mar  3 14:13:20 2011	(r33013)
+++ trunk/gui/app.c	Thu Mar  3 14:45:30 2011	(r33014)
@@ -106,24 +106,31 @@ static void appClearItem(wItem *item)
     item->tmp       = 0;
 }
 
+void appResetStruct(void)
+{
+    appMPlayer.NumberOfMainItems = -1;
+    appMPlayer.NumberOfBarItems  = -1;
+    appMPlayer.NumberOfMenuItems = -1;
+
+    appMPlayer.sub.x = -1;   // NOTE TO MYSELF: is this really necessary?
+    appMPlayer.sub.y = -1;   // NOTE TO MYSELF: is this really necessary?
+}
+
 void appInitStruct(void)
 {
     int i;
 
-    for (i = 0; i < appMPlayer.NumberOfMainItems; i++)
+    for (i = 0; i < appMPlayer.NumberOfMainItems + 1; i++)
         appClearItem(&appMPlayer.mainItems[i]);
-    for (i = 0; i < appMPlayer.NumberOfBarItems; i++)
+    for (i = 0; i < appMPlayer.NumberOfBarItems + 1; i++)
         appClearItem(&appMPlayer.barItems[i]);
-    for (i = 0; i < appMPlayer.NumberOfMenuItems; i++)
+    for (i = 0; i < appMPlayer.NumberOfMenuItems + 1; i++)
         appClearItem(&appMPlayer.menuItems[i]);
 
-    appMPlayer.NumberOfMainItems = -1;
     memset(appMPlayer.mainItems, 0, 256 * sizeof(wItem));
 
-    appMPlayer.NumberOfMenuItems = -1;
     memset(appMPlayer.menuItems, 0, 64 * sizeof(wItem));
 
-    appMPlayer.NumberOfBarItems = -1;
     memset(appMPlayer.barItems, 0, 256 * sizeof(wItem));
 
     appClearItem(&appMPlayer.main);
@@ -132,8 +139,6 @@ void appInitStruct(void)
     appClearItem(&appMPlayer.sub);
     appMPlayer.sub.width  = 0;
     appMPlayer.sub.height = 0;
-    appMPlayer.sub.x      = -1;
-    appMPlayer.sub.y      = -1;
 
     appClearItem(&appMPlayer.menuBase);
     appClearItem(&appMPlayer.menuSelected);
@@ -143,6 +148,8 @@ void appInitStruct(void)
     appMPlayer.main.R        = appMPlayer.main.G = appMPlayer.main.B = 0;
     appMPlayer.barIsPresent  = 0;
     appMPlayer.menuIsPresent = 0;
+
+    appResetStruct();
 }
 
 int appFindMessage(unsigned char *str)

Modified: trunk/gui/app.h
==============================================================================
--- trunk/gui/app.h	Thu Mar  3 14:13:20 2011	(r33013)
+++ trunk/gui/app.h	Thu Mar  3 14:45:30 2011	(r33014)
@@ -190,6 +190,7 @@ extern listItems appMPlayer;
 
 int appFindMessage(unsigned char *);
 void appInitStruct(void);
+void appResetStruct(void);
 void btnModify(int, float);
 void btnSet(int, int);
 

Modified: trunk/gui/interface.c
==============================================================================
--- trunk/gui/interface.c	Thu Mar  3 14:13:20 2011	(r33013)
+++ trunk/gui/interface.c	Thu Mar  3 14:45:30 2011	(r33014)
@@ -163,6 +163,8 @@ void guiInit( void )
  guiIntfStruct.Balance=50.0f;
  guiIntfStruct.StreamType=-1;
 
+ appResetStruct();
+
  memset( &gtkEquChannels,0,sizeof( gtkEquChannels ) );
 #ifdef CONFIG_DXR3
  if ( !gtkDXR3Device ) gtkDXR3Device=strdup( "/dev/em8300-0" );


More information about the MPlayer-cvslog mailing list