comparison gui/app.c @ 32927:edb972e22021

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.
author ib
date Thu, 03 Mar 2011 13:45:30 +0000
parents 7c205a5c2a9b
children 0ef78cd3063b
comparison
equal deleted inserted replaced
32926:7c205a5c2a9b 32927:edb972e22021
104 item->last_x = 0; 104 item->last_x = 0;
105 item->pressed = btnDisabled; 105 item->pressed = btnDisabled;
106 item->tmp = 0; 106 item->tmp = 0;
107 } 107 }
108 108
109 void appResetStruct(void)
110 {
111 appMPlayer.NumberOfMainItems = -1;
112 appMPlayer.NumberOfBarItems = -1;
113 appMPlayer.NumberOfMenuItems = -1;
114
115 appMPlayer.sub.x = -1; // NOTE TO MYSELF: is this really necessary?
116 appMPlayer.sub.y = -1; // NOTE TO MYSELF: is this really necessary?
117 }
118
109 void appInitStruct(void) 119 void appInitStruct(void)
110 { 120 {
111 int i; 121 int i;
112 122
113 for (i = 0; i < appMPlayer.NumberOfMainItems; i++) 123 for (i = 0; i < appMPlayer.NumberOfMainItems + 1; i++)
114 appClearItem(&appMPlayer.mainItems[i]); 124 appClearItem(&appMPlayer.mainItems[i]);
115 for (i = 0; i < appMPlayer.NumberOfBarItems; i++) 125 for (i = 0; i < appMPlayer.NumberOfBarItems + 1; i++)
116 appClearItem(&appMPlayer.barItems[i]); 126 appClearItem(&appMPlayer.barItems[i]);
117 for (i = 0; i < appMPlayer.NumberOfMenuItems; i++) 127 for (i = 0; i < appMPlayer.NumberOfMenuItems + 1; i++)
118 appClearItem(&appMPlayer.menuItems[i]); 128 appClearItem(&appMPlayer.menuItems[i]);
119 129
120 appMPlayer.NumberOfMainItems = -1;
121 memset(appMPlayer.mainItems, 0, 256 * sizeof(wItem)); 130 memset(appMPlayer.mainItems, 0, 256 * sizeof(wItem));
122 131
123 appMPlayer.NumberOfMenuItems = -1;
124 memset(appMPlayer.menuItems, 0, 64 * sizeof(wItem)); 132 memset(appMPlayer.menuItems, 0, 64 * sizeof(wItem));
125 133
126 appMPlayer.NumberOfBarItems = -1;
127 memset(appMPlayer.barItems, 0, 256 * sizeof(wItem)); 134 memset(appMPlayer.barItems, 0, 256 * sizeof(wItem));
128 135
129 appClearItem(&appMPlayer.main); 136 appClearItem(&appMPlayer.main);
130 appMPlayer.mainDecoration = 0; 137 appMPlayer.mainDecoration = 0;
131 138
132 appClearItem(&appMPlayer.sub); 139 appClearItem(&appMPlayer.sub);
133 appMPlayer.sub.width = 0; 140 appMPlayer.sub.width = 0;
134 appMPlayer.sub.height = 0; 141 appMPlayer.sub.height = 0;
135 appMPlayer.sub.x = -1;
136 appMPlayer.sub.y = -1;
137 142
138 appClearItem(&appMPlayer.menuBase); 143 appClearItem(&appMPlayer.menuBase);
139 appClearItem(&appMPlayer.menuSelected); 144 appClearItem(&appMPlayer.menuSelected);
140 145
141 appMPlayer.sub.R = appMPlayer.sub.G = appMPlayer.sub.B = 0; 146 appMPlayer.sub.R = appMPlayer.sub.G = appMPlayer.sub.B = 0;
142 appMPlayer.bar.R = appMPlayer.bar.G = appMPlayer.bar.B = 0; 147 appMPlayer.bar.R = appMPlayer.bar.G = appMPlayer.bar.B = 0;
143 appMPlayer.main.R = appMPlayer.main.G = appMPlayer.main.B = 0; 148 appMPlayer.main.R = appMPlayer.main.G = appMPlayer.main.B = 0;
144 appMPlayer.barIsPresent = 0; 149 appMPlayer.barIsPresent = 0;
145 appMPlayer.menuIsPresent = 0; 150 appMPlayer.menuIsPresent = 0;
151
152 appResetStruct();
146 } 153 }
147 154
148 int appFindMessage(unsigned char *str) 155 int appFindMessage(unsigned char *str)
149 { 156 {
150 int i; 157 int i;