Skip to content

Commit

Permalink
tr2: fix valgrind complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Feb 1, 2025
1 parent fa2b8e6 commit 1240537
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/libtrx/engine/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ typedef struct {
} M_STATE;

static int64_t m_AudioCallbackTime;
static SDL_AudioDeviceID m_AudioDevice;
static SDL_AudioDeviceID m_AudioDevice = 0;

static int M_PacketQueuePutPrivate(M_PACKET_QUEUE *q, AVPacket *pkt)
{
Expand Down Expand Up @@ -778,10 +778,13 @@ static void M_StreamComponentClose(M_STATE *is, int stream_index)
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
M_DecoderAbort(&is->auddec, &is->sampq);
SDL_CloseAudioDevice(m_AudioDevice);
M_DecoderShutdown(&is->auddec);
swr_free(&is->swr_ctx);
av_freep(&is->audio_buf1);
if (m_AudioDevice > 0) {
SDL_CloseAudioDevice(m_AudioDevice);
m_AudioDevice = 0;
}
is->audio_buf1_size = 0;
is->audio_buf = nullptr;

Expand Down
6 changes: 3 additions & 3 deletions src/tr2/decomp/savegame.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <stdio.h>
#include <string.h>

#define MAX_SG_BUFFER_SIZE 6272
#define SAVE_CREATURE (1 << 7)

#define SPECIAL_READ_WRITES \
Expand Down Expand Up @@ -875,7 +874,7 @@ void CreateSaveGameInfo(void)
g_SaveGame.num_key[3] = Inv_RequestItem(O_KEY_ITEM_4);

ResetSG();
memset(g_SaveGame.buffer, 0, sizeof(g_SaveGame.buffer));
memset(g_SaveGame.buffer, 0, MAX_SG_BUFFER_SIZE);

M_WriteS32(g_FlipStatus);
for (int32_t i = 0; i < MAX_FLIP_MAPS; i++) {
Expand Down Expand Up @@ -1057,7 +1056,8 @@ int32_t S_SaveGame(const int32_t slot_num)
const GF_LEVEL *const current_level =
GF_GetLevel(GFLT_MAIN, g_SaveGame.current_level);

sprintf(file_name, "%s", current_level->title);
memset(file_name, 0, 75);
snprintf(file_name, 75, "%s", current_level->title);
File_WriteData(fp, file_name, 75);
File_WriteS32(fp, g_SaveCounter);
M_WriteStartInfos(fp);
Expand Down
4 changes: 4 additions & 0 deletions src/tr2/game/shell/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ void Shell_Main(void)

void Shell_Shutdown(void)
{
SDL_DestroyWindow(g_SDLWindow);

GF_Shutdown();
GameString_Shutdown();
Console_Shutdown();
Expand All @@ -442,6 +444,8 @@ void Shell_Shutdown(void)
GameBuf_Shutdown();
Config_Shutdown();
EnumMap_Shutdown();

SDL_Quit();
}

const char *Shell_GetConfigPath(void)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/global/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define MAX_REQUESTER_ITEMS 24
#define MAX_SAVE_SLOTS 16
#define MAX_ASSAULT_TIMES 10
#define MAX_SG_BUFFER_SIZE 6272

#define DEATH_WAIT (5 * 2 * FRAMES_PER_SECOND) // = 300
#define DEATH_WAIT_INPUT (2 * FRAMES_PER_SECOND) // = 60
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/global/types_decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ typedef struct {
uint8_t num_puzzle[4];
uint8_t num_key[4];
uint16_t reserved;
char buffer[6272]; // MAX_SG_BUFFER_SIZE
char buffer[MAX_SG_BUFFER_SIZE];
} SAVEGAME_INFO;

typedef struct {
Expand Down

0 comments on commit 1240537

Please sign in to comment.