Skip to contentSkip to conversation

ui/cocoa: Fix clipboard text release

PATCH In review Akihiko Odaki 2 participants 2 messages Jun 14, 2022 – Jun 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/cocoa: Fix clipboard text release

[-NSPasteboard dataForType:] returns an autoreleased NSString, and callings its release method will result in double-free when the global autorelease pool is released. Use NSAutoreleasePool to release it properly.

---
 ui/cocoa.m | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ui/cocoa.m +3 -1
index 84c84e98fc5..6a4dccff7f0 100644
@@ -1894,16 +1894,18 @@ static void cocoa_clipboard_notify(Notifier *notifier, void *data)
 static void cocoa_clipboard_request(QemuClipboardInfo *info,
                                     QemuClipboardType type)
 {
+    NSAutoreleasePool *pool;
     NSData *text;
 
     switch (type) {
     case QEMU_CLIPBOARD_TYPE_TEXT:
+        pool = [[NSAutoreleasePool alloc] init];
         text = [[NSPasteboard generalPasteboard] dataForType:NSPasteboardTypeString];
         if (text) {
             qemu_clipboard_set_data(&cbpeer, info, type,
                                     [text length], [text bytes], true);
-            [text release];
         }
+        [pool release];
         break;
     default:
         break;
Signature · 1 line
2.32.1 (Apple Git-133)