From 824256db6dc2c407a9557b7a195c97bd556358dd Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 29 Jun 2021 21:18:42 +1000 Subject: [PATCH] [mac] Small memory leak fixes --- v2/internal/ffenestri/ffenestri_darwin.c | 9 ++++++++- v2/internal/ffenestri/traymenu_darwin.c | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 6e63f5ce..18c8fb08 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -102,6 +102,7 @@ struct Application { id mouseDownMonitor; id mouseUpMonitor; int activationPolicy; + id pool; // Window Data const char *title; @@ -1451,6 +1452,7 @@ void processDialogIcons(struct hashmap_s *hashmap, const unsigned char *dialogIc // Create the icon and add to the hashmap id imageData = ((id(*)(id, SEL, const unsigned char *, int))objc_msgSend)(c("NSData"), s("dataWithBytes:length:"), data, length); id dialogImage = ALLOC("NSImage"); + msg_reg(dialogImage, s("autorelease")); msg_id(dialogImage, s("initWithData:"), imageData); hashmap_put(hashmap, (const char *)name, strlen((const char *)name), dialogImage); } @@ -1622,7 +1624,9 @@ void Run(struct Application *app, int argc, char **argv) { MEMFREE(temp); // Add code that sets up the initial state, EG: State Stores. - temp = concat(internalCode, getInitialState(app)); + const char *initialState = getInitialState(app); + temp = concat(internalCode, initialState); + MEMFREE(initialState); MEMFREE(internalCode); internalCode = temp; @@ -1723,6 +1727,7 @@ id createImageFromBase64Data(const char *data, bool isTemplateImage) { imageData = ((id(*)(id, SEL, id, int))objc_msgSend)(nsdata, s("initWithBase64EncodedString:options:"), str(BrokenImage), 0); } id result = ALLOC("NSImage"); + msg_reg(result, s("autorelease")); msg_id(result, s("initWithData:"), imageData); if( isTemplateImage ) { @@ -1801,6 +1806,8 @@ void* NewApplication(const char *title, int width, int height, int resizable, in result->running = false; + result->pool = objc_msgSend(c("NSAutoreleasePool"), s("new")); + return (void*) result; } diff --git a/v2/internal/ffenestri/traymenu_darwin.c b/v2/internal/ffenestri/traymenu_darwin.c index a78dadd2..2ae3e44a 100644 --- a/v2/internal/ffenestri/traymenu_darwin.c +++ b/v2/internal/ffenestri/traymenu_darwin.c @@ -140,6 +140,7 @@ void ShowTrayMenu(TrayMenu* trayMenu) { // Create delegate id trayMenuDelegate = msg_reg((id)trayMenuDelegateClass, s("new")); + msg_reg(trayMenuDelegate, s("autorelease")); msg_id(menu, s("setDelegate:"), trayMenuDelegate); objc_setAssociatedObject(trayMenuDelegate, "menu", menu, OBJC_ASSOCIATION_ASSIGN);