Skip to content

Commit

Permalink
tr2/level: fix game crash when injections missing
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Dec 1, 2024
1 parent 13a83b0 commit 181c3a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libtrx/virtual_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ VFILE *VFile_CreateFromBuffer(const char *data, size_t size)

void VFile_Close(VFILE *file)
{
ASSERT(file != NULL);
Memory_FreePointer(&file->content);
Memory_FreePointer(&file);
}
Expand Down
8 changes: 7 additions & 1 deletion src/tr2/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "global/utils.h"

#include <libtrx/benchmark.h>
#include <libtrx/debug.h>
#include <libtrx/log.h>
#include <libtrx/memory.h>
#include <libtrx/utils.h>
Expand Down Expand Up @@ -433,10 +434,14 @@ void Inject_Cleanup(void)
}

BENCHMARK *const benchmark = Benchmark_Start();
ASSERT(m_Injections != NULL);

for (int32_t i = 0; i < m_NumInjections; i++) {
INJECTION *const injection = &m_Injections[i];
VFile_Close(injection->fp);
if (injection->fp != NULL) {
VFile_Close(injection->fp);
injection->fp = NULL;
}
}

for (int32_t i = 0; i < IDT_NUMBER_OF; i++) {
Expand All @@ -445,4 +450,5 @@ void Inject_Cleanup(void)

Memory_FreePointer(&m_Injections);
Benchmark_End(benchmark, NULL);
m_NumInjections = 0;
}

0 comments on commit 181c3a0

Please sign in to comment.