From 8856fcbcebf5f72bbfdc4537e743c40bfe0e0b6d Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Tue, 2 Mar 2021 07:11:21 -0300 Subject: [PATCH] Use g_new0 and g_free to generate raw strings --- plugins/windows-notification/api/include/converter.hpp | 3 ++- plugins/windows-notification/api/src/converter.cpp | 2 +- .../api/src/gobject/winrt-toast-notification.cpp | 4 +++- plugins/windows-notification/api/src/gobject/winrt.cpp | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/windows-notification/api/include/converter.hpp b/plugins/windows-notification/api/include/converter.hpp index 0eb1488d..1bfe21c4 100644 --- a/plugins/windows-notification/api/include/converter.hpp +++ b/plugins/windows-notification/api/include/converter.hpp @@ -2,6 +2,7 @@ #include #include +#include std::wstring sview_to_wstr(const std::string_view str); -char* wsview_to_char(const std::wstring_view wstr); \ No newline at end of file +gchar* wsview_to_char(const std::wstring_view wstr); \ No newline at end of file diff --git a/plugins/windows-notification/api/src/converter.cpp b/plugins/windows-notification/api/src/converter.cpp index 67a52071..634ef0c4 100644 --- a/plugins/windows-notification/api/src/converter.cpp +++ b/plugins/windows-notification/api/src/converter.cpp @@ -10,7 +10,7 @@ char* wsview_to_char(const std::wstring_view wstr) return nullptr; } int final_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr); - char* strTo = new char[final_size + 1]{ 0 }; + gchar* strTo = g_new0(gchar, final_size + 1); WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), strTo, final_size, nullptr, nullptr); return strTo; } diff --git a/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp b/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp index c8ec3027..c0018936 100644 --- a/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp +++ b/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp @@ -270,7 +270,9 @@ winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(win } } - callback(wsview_to_char(arguments), nullptr /* user_input */ , 0 /* user_input.size() */, context); + auto args = wsview_to_char(arguments); + callback_data->callback(args, nullptr /* user_input */ , 0 /* user_input.size() */, callback_data->context); + g_free(args); }); callback_data->SetToken(winrt_event_token_new_from_token(&token)); diff --git a/plugins/windows-notification/api/src/gobject/winrt.cpp b/plugins/windows-notification/api/src/gobject/winrt.cpp index 7c95bbae..1b9965aa 100644 --- a/plugins/windows-notification/api/src/gobject/winrt.cpp +++ b/plugins/windows-notification/api/src/gobject/winrt.cpp @@ -14,7 +14,7 @@ gboolean winrt_InitApartment() { auto message = wsview_to_char(e.message()); std::cerr << message << '\n'; - delete[] message; + g_free(message); if (e.code() == -2147417850 /* RPC_E_CHANGED_MODE */) // harmless { return true;