Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in WrappedText #4043

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions soh/soh/UIWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <libultraship/libultra/types.h>
#include "soh/Enhancements/cosmetics/CosmeticsEditor.h"

#ifdef _MSC_VER
#define strdup _strdup
#endif

namespace UIWidgets {

// MARK: - Layout Helper
Expand All @@ -28,7 +32,7 @@ namespace UIWidgets {
std::string newText(text);
const size_t tipLength = newText.length();
int lastSpace = -1;
int currentLineLength = 0;
unsigned int currentLineLength = 0;
for (unsigned int currentCharacter = 0; currentCharacter < tipLength; currentCharacter++) {
if (newText[currentCharacter] == '\n') {
currentLineLength = 0;
Expand Down Expand Up @@ -56,15 +60,19 @@ namespace UIWidgets {
void SetLastItemHoverText(const std::string& text) {
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
char* hoverTextWrapped = WrappedText(text, 60);
ImGui::Text("%s", hoverTextWrapped);
free(hoverTextWrapped);
ImGui::EndTooltip();
}
}

void SetLastItemHoverText(const char* text) {
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
char* hoverTextWrapped = WrappedText(text, 60);
ImGui::Text("%s", hoverTextWrapped);
free(hoverTextWrapped);
ImGui::EndTooltip();
}
}
Expand All @@ -75,7 +83,9 @@ namespace UIWidgets {
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?");
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
char* hoverTextWrapped = WrappedText(text, 60);
ImGui::Text("%s", hoverTextWrapped);
free(hoverTextWrapped);
ImGui::EndTooltip();
}
}
Expand All @@ -85,7 +95,9 @@ namespace UIWidgets {
ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?");
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%s", WrappedText(text, 60));
char* hoverTextWrapped = WrappedText(text, 60);
ImGui::Text("%s", hoverTextWrapped);
free(hoverTextWrapped);
ImGui::EndTooltip();
}
}
Expand All @@ -95,7 +107,9 @@ namespace UIWidgets {

void Tooltip(const char* text) {
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("%s", WrappedText(text));
char* tooltipWrapped = WrappedText(text);
ImGui::SetTooltip("%s", tooltipWrapped);
free(tooltipWrapped);
}
}

Expand Down
Loading