Fix memory leaks in MessageViewer and audio_load (#6124)
Add destructor to MessageViewer to free allocated buffers Free individual strings from ResourceMgr_ListFiles before freeing the array in audio_load.c
This commit is contained in:
@@ -26,6 +26,12 @@ void MessageViewer::InitElement() {
|
|||||||
mCustomMessageBuf = static_cast<char*>(calloc(MAX_STRING_SIZE, sizeof(char)));
|
mCustomMessageBuf = static_cast<char*>(calloc(MAX_STRING_SIZE, sizeof(char)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageViewer::~MessageViewer() {
|
||||||
|
free(mTableIdBuf);
|
||||||
|
free(mTextIdBuf);
|
||||||
|
free(mCustomMessageBuf);
|
||||||
|
}
|
||||||
|
|
||||||
void MessageViewer::DrawElement() {
|
void MessageViewer::DrawElement() {
|
||||||
ImGui::BeginDisabled(CVarGetInteger(CVAR_SETTING("DisableChanges"), 0));
|
ImGui::BeginDisabled(CVarGetInteger(CVAR_SETTING("DisableChanges"), 0));
|
||||||
ImGui::Text("Table ID");
|
ImGui::Text("Table ID");
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class MessageViewer final : public Ship::GuiWindow {
|
|||||||
void DrawElement() override;
|
void DrawElement() override;
|
||||||
void UpdateElement() override;
|
void UpdateElement() override;
|
||||||
|
|
||||||
virtual ~MessageViewer() = default;
|
~MessageViewer() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DisplayExistingMessage() const;
|
void DisplayExistingMessage() const;
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ extern "C" void ResourceMgr_UnloadResource(const char* resName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OTRTODO: There is probably a more elegant way to go about this...
|
// OTRTODO: There is probably a more elegant way to go about this...
|
||||||
// Kenix: This is definitely leaking memory when it's called.
|
// Caller must free each string and the array itself when done.
|
||||||
extern "C" char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize) {
|
extern "C" char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize) {
|
||||||
auto lst = Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles(searchMask);
|
auto lst = Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles(searchMask);
|
||||||
char** result = (char**)malloc(lst->size() * sizeof(char*));
|
char** result = (char**)malloc(lst->size() * sizeof(char*));
|
||||||
|
|||||||
@@ -1352,6 +1352,9 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
|||||||
seqCachePolicyMap[sDat.seqNumber] = sDat.cachePolicy;
|
seqCachePolicyMap[sDat.seqNumber] = sDat.cachePolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < seqListSize; i++) {
|
||||||
|
free(seqList[i]);
|
||||||
|
}
|
||||||
free(seqList);
|
free(seqList);
|
||||||
|
|
||||||
// 2S2H [Streamed Audio] We need to load the custom songs after the fonts because streamed songs will use a hash to
|
// 2S2H [Streamed Audio] We need to load the custom songs after the fonts because streamed songs will use a hash to
|
||||||
@@ -1369,6 +1372,9 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
|||||||
fontMap[sf->fntIndex] = strdup(fntList[i]);
|
fontMap[sf->fntIndex] = strdup(fntList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < fntListSize; i++) {
|
||||||
|
free(fntList[i]);
|
||||||
|
}
|
||||||
free(fntList);
|
free(fntList);
|
||||||
|
|
||||||
int customFontStart = fntListSize;
|
int customFontStart = fntListSize;
|
||||||
@@ -1377,6 +1383,9 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
|||||||
sf->fntIndex = i;
|
sf->fntIndex = i;
|
||||||
fontMap[i] = strdup(customFntList[i - customFontStart]);
|
fontMap[i] = strdup(customFntList[i - customFontStart]);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < customFntListSize; i++) {
|
||||||
|
free(customFntList[i]);
|
||||||
|
}
|
||||||
free(customFntList);
|
free(customFntList);
|
||||||
|
|
||||||
// 2S2H Port I think we need to take use seqListSize because entry 0x7A is missing.
|
// 2S2H Port I think we need to take use seqListSize because entry 0x7A is missing.
|
||||||
@@ -1432,6 +1441,9 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
|
|||||||
seqNum++;
|
seqNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < customSeqListSize; i++) {
|
||||||
|
free(customSeqList[i]);
|
||||||
|
}
|
||||||
free(customSeqList);
|
free(customSeqList);
|
||||||
|
|
||||||
numFonts = fntListSize;
|
numFonts = fntListSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user