Fixed memory leaks at linux emulator shutdown

This commit is contained in:
Silvano Seva 2022-07-01 14:39:28 +02:00
parent 5f40ceceb3
commit 28929aab90
3 changed files with 22 additions and 20 deletions

View File

@ -32,7 +32,7 @@
#include <string.h> #include <string.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
void *frameBuffer; /* Pointer to framebuffer */ void *frameBuffer = NULL; /* Pointer to framebuffer */
bool inProgress; /* Flag to signal when rendering is in progress */ bool inProgress; /* Flag to signal when rendering is in progress */
/* /*
@ -73,6 +73,7 @@ uint32_t fetchPixelFromFb(unsigned int x, unsigned int y)
pixel = 0xFF000000 | (px << 16) | (px << 8) | px; pixel = 0xFF000000 | (px << 16) | (px << 8) | px;
#endif #endif
return pixel; return pixel;
} }
@ -114,12 +115,11 @@ void display_init()
void display_terminate() void display_terminate()
{ {
while (inProgress) while (inProgress){ } /* Wait until current render finishes */
{} /* Wait until current render finishes */
printf("Terminating SDL display emulator, goodbye!\n");
free(frameBuffer);
chan_close(&fb_sync); chan_close(&fb_sync);
chan_terminate(&fb_sync); chan_terminate(&fb_sync);
if(frameBuffer != NULL) free(frameBuffer);
frameBuffer = NULL;
} }
void display_renderRows(uint8_t startRow, uint8_t endRow) void display_renderRows(uint8_t startRow, uint8_t endRow)

View File

@ -375,6 +375,10 @@ void sdlEngine_run()
} }
} }
printf("Terminating SDL display emulator, goodbye!\n");
SDL_DestroyTexture(displayTexture);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
} }

View File

@ -50,8 +50,6 @@ void platform_init()
void platform_terminate() void platform_terminate()
{ {
printf("Platform terminate\n"); printf("Platform terminate\n");
gfx_terminate();
exit(0); exit(0);
} }