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

Fixed memory leak in C++ string formatting #32

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ protected override void CppCreateFormatMethod(CodeStringBuilder builderCpp, stri
builderCpp.AppendLine($"size_t needed = _swprintf_p(nullptr, 0, {localizationStr}->Data(), {formatParameters});");
builderCpp.AppendLine($"wchar_t *buffer = new wchar_t[needed + 1];");
builderCpp.AppendLine($"_swprintf_p(buffer, needed + 1, {localizationStr}->Data(), {formatParameters});");
builderCpp.AppendLine($"return ref new String(buffer);");
builderCpp.AppendLine($"auto const string = ref new String(buffer);");
builderCpp.AppendLine($"delete[] buffer;");
builderCpp.AppendLine($"return string;");
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ protected override void CppCreateFormatMethod(CodeStringBuilder builderCpp, stri
builderCpp.AppendLine($"size_t needed = _swprintf_p(nullptr, 0, {localizationStr}.c_str(), {formatParameters});");
builderCpp.AppendLine($"wchar_t *buffer = new wchar_t[needed + 1];");
builderCpp.AppendLine($"_swprintf_p(buffer, needed + 1, {localizationStr}.c_str(), {formatParameters});");
builderCpp.AppendLine($"return hstring(buffer);");
builderCpp.AppendLine($"hstring const string{ buffer };");
builderCpp.AppendLine($"delete[] buffer;");
builderCpp.AppendLine($"return string;");
}
}
else
Expand Down