clean up memory leaks
This commit is contained in:
parent
427ac1368f
commit
161136cd57
49
main.c
49
main.c
|
@ -70,7 +70,7 @@ struct NewWindow aboutWindowLayout = {
|
||||||
40, 40,
|
40, 40,
|
||||||
ABOUT_WINDOW_WIDTH, ABOUT_WINDOW_HEIGHT,
|
ABOUT_WINDOW_WIDTH, ABOUT_WINDOW_HEIGHT,
|
||||||
0, 1,
|
0, 1,
|
||||||
IDCMP_REFRESHWINDOW | IDCMP_CLOSEWINDOW | BUTTONIDCMP,
|
IDCMP_CLOSEWINDOW,
|
||||||
WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE,
|
WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -133,6 +133,7 @@ struct Menu *menu;
|
||||||
struct Device *TimerBase;
|
struct Device *TimerBase;
|
||||||
struct timerequest *TimerIO;
|
struct timerequest *TimerIO;
|
||||||
struct timeval currentSystemTime;
|
struct timeval currentSystemTime;
|
||||||
|
struct MsgPort *timerPort;
|
||||||
|
|
||||||
// sound stuff
|
// sound stuff
|
||||||
// get that bell
|
// get that bell
|
||||||
|
@ -155,6 +156,7 @@ ULONG timerStartTime = 0, timerDistance, timerBuild;
|
||||||
BOOL timerIsRunning = FALSE;
|
BOOL timerIsRunning = FALSE;
|
||||||
BOOL timerStarted = FALSE;
|
BOOL timerStarted = FALSE;
|
||||||
BOOL terminated = FALSE;
|
BOOL terminated = FALSE;
|
||||||
|
BOOL openAboutWindowNext = FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize system stuff.
|
* Initialize system stuff.
|
||||||
|
@ -163,8 +165,6 @@ BOOL terminated = FALSE;
|
||||||
// parameter.
|
// parameter.
|
||||||
// http://www.hipooniosamigasite.org/amigadocs/files/LOON-DOCS-DISKS/LOON5/LatticeC.pt3
|
// http://www.hipooniosamigasite.org/amigadocs/files/LOON-DOCS-DISKS/LOON5/LatticeC.pt3
|
||||||
int setup(void) {
|
int setup(void) {
|
||||||
struct MsgPort *timerPort;
|
|
||||||
|
|
||||||
// make sure the font exists on the computer
|
// make sure the font exists on the computer
|
||||||
// http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_3._guide/node0308.html
|
// http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_3._guide/node0308.html
|
||||||
if (NULL == (topaz80Font = OpenFont(&Topaz80))) {
|
if (NULL == (topaz80Font = OpenFont(&Topaz80))) {
|
||||||
|
@ -218,15 +218,12 @@ int setup(void) {
|
||||||
*/
|
*/
|
||||||
void teardown(void) {
|
void teardown(void) {
|
||||||
// http://amigadev.elowar.com/read/ADCD_2.1/Devices_Manual_guide/node0196.html
|
// http://amigadev.elowar.com/read/ADCD_2.1/Devices_Manual_guide/node0196.html
|
||||||
struct MsgPort *tempTimerPort;
|
|
||||||
|
|
||||||
if (TimerIO) {
|
if (TimerIO) {
|
||||||
CloseDevice((struct IORequest *)TimerIO);
|
CloseDevice((struct IORequest *)TimerIO);
|
||||||
tempTimerPort = TimerIO->tr_node.io_Message.mn_ReplyPort;
|
DeleteExtIO((struct IORequest *)TimerIO);
|
||||||
|
|
||||||
if (tempTimerPort) {
|
|
||||||
DeletePort(tempTimerPort);
|
|
||||||
}
|
}
|
||||||
|
if (timerPort) {
|
||||||
|
DeletePort(timerPort);
|
||||||
}
|
}
|
||||||
// all right, then. keep your secrets.
|
// all right, then. keep your secrets.
|
||||||
if (visualInfo) FreeVisualInfo(visualInfo);
|
if (visualInfo) FreeVisualInfo(visualInfo);
|
||||||
|
@ -527,6 +524,14 @@ int openAboutWindow(void) {
|
||||||
|
|
||||||
ULONG windowSignal;
|
ULONG windowSignal;
|
||||||
BOOL closeAbout = FALSE;
|
BOOL closeAbout = FALSE;
|
||||||
|
|
||||||
|
// Something is causing a small memory leak when I do this and I don't know
|
||||||
|
// what it is. CodeWatcher reports a bunch of 40 byte blocks, most likely
|
||||||
|
// Intuition messages.
|
||||||
|
//
|
||||||
|
// nope, false positive, checked with avail before and after running and
|
||||||
|
// the used/free counts are exactly the same:
|
||||||
|
// https://eab.abime.net/showthread.php?t=104360
|
||||||
aboutWindow = OpenWindow(&aboutWindowLayout);
|
aboutWindow = OpenWindow(&aboutWindowLayout);
|
||||||
|
|
||||||
if (!aboutWindow) {
|
if (!aboutWindow) {
|
||||||
|
@ -584,7 +589,8 @@ int openAboutWindow(void) {
|
||||||
while (!closeAbout) {
|
while (!closeAbout) {
|
||||||
Wait(windowSignal);
|
Wait(windowSignal);
|
||||||
|
|
||||||
while (!closeAbout && (iMessage = GT_GetIMsg(aboutWindow->UserPort))) {
|
while (iMessage = GT_GetIMsg(aboutWindow->UserPort)) {
|
||||||
|
if (!closeAbout) {
|
||||||
switch (iMessage->Class) {
|
switch (iMessage->Class) {
|
||||||
case IDCMP_CLOSEWINDOW:
|
case IDCMP_CLOSEWINDOW:
|
||||||
closeAbout = TRUE;
|
closeAbout = TRUE;
|
||||||
|
@ -595,6 +601,10 @@ int openAboutWindow(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure messages are garbage collected
|
||||||
|
GT_ReplyIMsg(iMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveGList(aboutWindow, glist, -1);
|
RemoveGList(aboutWindow, glist, -1);
|
||||||
|
@ -648,10 +658,7 @@ void handleIntuitionMessage(struct IntuiMessage *iMessage) {
|
||||||
terminated = TRUE;
|
terminated = TRUE;
|
||||||
break;
|
break;
|
||||||
case MENU_ABOUT_ID:
|
case MENU_ABOUT_ID:
|
||||||
// yes, this blocks, deal with it
|
openAboutWindowNext = TRUE;
|
||||||
// it also returns non-zero if something goes wrong.
|
|
||||||
// in that case, kill the program
|
|
||||||
if (openAboutWindow()) terminated = TRUE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -833,14 +840,26 @@ int main() {
|
||||||
|
|
||||||
if (foundSignals & windowSignal) {
|
if (foundSignals & windowSignal) {
|
||||||
// drain the window event queue
|
// drain the window event queue
|
||||||
while ((!terminated) && (iMessage = GT_GetIMsg(window->UserPort))) {
|
while (iMessage = GT_GetIMsg(window->UserPort)) {
|
||||||
|
if (!terminated) {
|
||||||
handleIntuitionMessage(iMessage);
|
handleIntuitionMessage(iMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we don't reply, the event won't be garbage collected.
|
||||||
|
// we still have to drain any other messages that show up
|
||||||
|
GT_ReplyIMsg(iMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((foundSignals & timerSignal) && timerIsRunning) {
|
if ((foundSignals & timerSignal) && timerIsRunning) {
|
||||||
handleTimerMessage();
|
handleTimerMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (openAboutWindowNext) {
|
||||||
|
if (openAboutWindow()) terminated = TRUE;
|
||||||
|
|
||||||
|
openAboutWindowNext = FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearUI();
|
clearUI();
|
||||||
|
|
Loading…
Reference in New Issue