diff options
author | Tor Lillqvist <tml@collabora.com> | 2018-10-25 21:27:48 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-10-25 21:28:13 +0300 |
commit | 16a805e290e5a276f44728cf428efe7f31de0622 (patch) | |
tree | 01704dc57116fac969c39ca17e72b8a5e6fb2b99 /gtk | |
parent | 4724aa0cf78f3aedf7f7f4222d251ef8395d5523 (diff) |
Fix some memory management foo
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/mobile.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/gtk/mobile.cpp b/gtk/mobile.cpp index 760d62c10..a45ebf990 100644 --- a/gtk/mobile.cpp +++ b/gtk/mobile.cpp @@ -27,9 +27,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <cstdlib> +#include <cstring> #include <iostream> #include <thread> +#include <string.h> + #include <gtk/gtk.h> #include <webkit2/webkit2.h> @@ -56,7 +60,7 @@ static void send2JS_ready_callback(GObject *source_object, GAsyncResult *res, gpointer user_data) { - g_free(user_data); + free(user_data); } static void send2JS(const std::vector<char>& buffer) @@ -102,7 +106,7 @@ static void send2JS(const std::vector<char>& buffer) data.push_back(0); js = "window.TheFakeWebSocket.onmessage({'data': '"; - js = js + std::string(buffer.data()); + js = js + std::string(buffer.data(), buffer.size()); js = js + "'});"; } @@ -228,13 +232,15 @@ static void handle_lool_message(WebKitUserContentManager *manager, else { // As above - std::thread([&] + char *string_copy = strdup(string_value); + std::thread([=] { struct pollfd pollfd; pollfd.fd = fakeClientFd; pollfd.events = POLLOUT; fakeSocketPoll(&pollfd, 1, -1); - fakeSocketWrite(fakeClientFd, string_value, strlen(string_value)); + fakeSocketWrite(fakeClientFd, string_copy, strlen(string_copy)); + free(string_copy); }).detach(); } g_free(string_value); |