# HG changeset patch # User ib # Date 1299159930 0 # Node ID edb972e220218fb5a43156ee2d4e14ec22621667 # Parent 7c205a5c2a9bbfe030fb6cbe87e9eaf793e3521a 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. diff -r 7c205a5c2a9b -r edb972e22021 gui/app.c --- a/gui/app.c Thu Mar 03 13:13:20 2011 +0000 +++ b/gui/app.c Thu Mar 03 13:45:30 2011 +0000 @@ -106,24 +106,31 @@ 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 @@ 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 @@ appMPlayer.main.R = appMPlayer.main.G = appMPlayer.main.B = 0; appMPlayer.barIsPresent = 0; appMPlayer.menuIsPresent = 0; + + appResetStruct(); } int appFindMessage(unsigned char *str) diff -r 7c205a5c2a9b -r edb972e22021 gui/app.h --- a/gui/app.h Thu Mar 03 13:13:20 2011 +0000 +++ b/gui/app.h Thu Mar 03 13:45:30 2011 +0000 @@ -190,6 +190,7 @@ int appFindMessage(unsigned char *); void appInitStruct(void); +void appResetStruct(void); void btnModify(int, float); void btnSet(int, int); diff -r 7c205a5c2a9b -r edb972e22021 gui/interface.c --- a/gui/interface.c Thu Mar 03 13:13:20 2011 +0000 +++ b/gui/interface.c Thu Mar 03 13:45:30 2011 +0000 @@ -163,6 +163,8 @@ guiIntfStruct.Balance=50.0f; guiIntfStruct.StreamType=-1; + appResetStruct(); + memset( >kEquChannels,0,sizeof( gtkEquChannels ) ); #ifdef CONFIG_DXR3 if ( !gtkDXR3Device ) gtkDXR3Device=strdup( "/dev/em8300-0" );