Fix animation memory leak
This commit is contained in:
+12
-5
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#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
|
#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 ))
|
#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;
|
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;
|
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);
|
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 )
|
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 );
|
free( g_libsm64_mario_animations );
|
||||||
g_libsm64_mario_animations = NULL;
|
g_libsm64_mario_animations = NULL;
|
||||||
|
s_num_entries = 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user