Fix animation memory leak

This commit is contained in:
jaburns
2020-10-27 13:30:35 -06:00
parent c74ab070e6
commit 0496684610
+12 -5
View File
@@ -2,7 +2,8 @@
#include <stdlib.h>
struct Animation *g_libsm64_mario_animations;
static uint32_t s_num_entries = 0;
struct Animation *g_libsm64_mario_animations = NULL;
#define ANIM_DATA_ADDRESS 0x004EC000
@@ -34,12 +35,12 @@ void load_mario_anims_from_rom( uint8_t *rom )
#define GET_SIZE( n ) (read_u32_be(&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->size ))
uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS;
uint32_t num_entries = read_u32_be( read_ptr );
s_num_entries = read_u32_be( read_ptr );
g_libsm64_mario_animations = malloc( num_entries * sizeof( struct Animation ));
g_libsm64_mario_animations = malloc( s_num_entries * sizeof( struct Animation ));
struct Animation *anims = g_libsm64_mario_animations;
for( int i = 0; i < num_entries; ++i )
for( int i = 0; i < s_num_entries; ++i )
{
read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i);
@@ -81,7 +82,13 @@ void load_mario_anims_from_rom( uint8_t *rom )
void unload_mario_anims( void )
{
// TODO free index and values arrays
for( int i = 0; i < s_num_entries; ++i )
{
free( g_libsm64_mario_animations[i].index );
free( g_libsm64_mario_animations[i].values );
}
free( g_libsm64_mario_animations );
g_libsm64_mario_animations = NULL;
s_num_entries = 0;
}