From 9ce7bcefe6bb45b0d0db8ecbe1d770c5b8e3d6e0 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 18 Jun 2017 15:51:39 -0500 Subject: [PATCH] don't free memory that we want to read later --- ui/ui_darwin.go | 22 ++++++++-------------- ui/ui_darwin.m | 1 + 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ui/ui_darwin.go b/ui/ui_darwin.go index b50b102..823a6f0 100644 --- a/ui/ui_darwin.go +++ b/ui/ui_darwin.go @@ -2,7 +2,6 @@ package ui import ( "log" - "unsafe" "github.com/jordanorelli/dws/events" ) @@ -50,26 +49,21 @@ func (ui *cocoaUI) forwardEvent(e events.BackgroundEvent) { case events.SetRootEvent: cpath := C.CString(v.Path) - defer C.free(unsafe.Pointer(cpath)) C.bg_set_root(cpath) case events.BeginRequestEvent: cpath := C.CString(v.Path) - defer C.free(unsafe.Pointer(cpath)) - - req := &C.struct_RequestMeta{ - seq: C.int(v.Seq), - path: cpath, - } - + req := (*C.struct_RequestMeta)(C.malloc(C.sizeof_struct_RequestMeta)) + req.seq = C.int(v.Seq) + req.path = cpath C.bg_received_request(req) case events.EndRequestEvent: - C.bg_sent_response(&C.struct_ResponseMeta{ - seq: C.int(v.Seq), - status: C.int(v.Status), - bytes: C.int(v.Bytes), - }) + res := (*C.struct_ResponseMeta)(C.malloc(C.sizeof_struct_ResponseMeta)) + res.seq = C.int(v.Seq) + res.status = C.int(v.Status) + res.bytes = C.int(v.Bytes) + C.bg_sent_response(res) } } diff --git a/ui/ui_darwin.m b/ui/ui_darwin.m index 9355f20..d744fbb 100644 --- a/ui/ui_darwin.m +++ b/ui/ui_darwin.m @@ -26,6 +26,7 @@ void bg_shutdown() { void bg_set_root(char *path) { id listener = [[EventBridge shared] listener]; [listener serverDidSetRoot:[NSString stringWithUTF8String:path]]; + free(path); } void bg_received_request(RequestMeta *meta) {