From 19df09dddcd404764880b8d802101019737d14c8 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 12 Feb 2024 13:15:57 +0100 Subject: [PATCH] - [FIX] Small memory leak fixed --- gif.c | 3 +++ jdraw8.cpp | 10 +++++----- jdraw8.h | 2 +- modulesequence.cpp | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gif.c b/gif.c index 3d5859d..6a3cd51 100644 --- a/gif.c +++ b/gif.c @@ -434,6 +434,9 @@ static unsigned char* process_gif_stream(unsigned char *buffer, unsigned short* // sizeof( screen_descriptor_t ) = 8! READ(&screen_descriptor, 7); + if (w) *w = screen_descriptor.width; + if (h) *h = screen_descriptor.height; + color_resolution_bits = ( ( screen_descriptor.fields & 0x70 ) >> 4 ) + 1; if ( screen_descriptor.fields & 0x80 ) diff --git a/jdraw8.cpp b/jdraw8.cpp index 7df4f90..8e77a91 100644 --- a/jdraw8.cpp +++ b/jdraw8.cpp @@ -50,9 +50,9 @@ void JD8_ClearScreen(Uint8 color) { memset( screen, color, 64000 ); } -JD8_Surface JD8_NewSurface() { - JD8_Surface surface = (JD8_Surface)malloc( 64000 ); - memset( surface, 0, 64000 ); +JD8_Surface JD8_NewSurface(const int w, const int h) { + JD8_Surface surface = (JD8_Surface)malloc( w * h ); + memset( surface, 0, w*h ); return surface; } @@ -70,8 +70,8 @@ JD8_Surface JD8_LoadSurface(const char *file) { exit(1); } - JD8_Surface image = JD8_NewSurface(); - memcpy(image, pixels, 64000); + JD8_Surface image = JD8_NewSurface(w, h); + memcpy(image, pixels, w * h); free(pixels); return image; diff --git a/jdraw8.h b/jdraw8.h index d76e4a0..5045d29 100644 --- a/jdraw8.h +++ b/jdraw8.h @@ -16,7 +16,7 @@ void JD8_Quit(); void JD8_ClearScreen(Uint8 color); -JD8_Surface JD8_NewSurface(); +JD8_Surface JD8_NewSurface(const int w, const int h); JD8_Surface JD8_LoadSurface(const char *file); diff --git a/modulesequence.cpp b/modulesequence.cpp index 27afb4c..19b75e5 100644 --- a/modulesequence.cpp +++ b/modulesequence.cpp @@ -57,7 +57,7 @@ namespace module { bool eixir = false; - fondo_temp = JD8_NewSurface(); + fondo_temp = JD8_NewSurface(320, 200); JD8_BlitToSurface(0, 0, fondo, 0, 0, 320, 200, fondo_temp); JD8_Blit(fondo_temp);