Skip to content

Commit a2ecd64

Browse files
committed
Minor fixes
1 parent 1704573 commit a2ecd64

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/_macosx.m

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <objc/NSObjCRuntime.h>
21
#define PY_SSIZE_T_CLEAN
32
#include <Cocoa/Cocoa.h>
43
#include <ApplicationServices/ApplicationServices.h>
@@ -639,27 +638,25 @@ int set_icon(PyObject* icon_path) {
639638
Py_DECREF(icon_path);
640639
return -1;
641640
}
642-
NSString* ns_icon_path = [NSString stringWithUTF8String: icon_path_ptr];
643-
if (!ns_icon_path) {
644-
Py_DECREF(icon_path);
645-
PyErr_SetString(PyExc_RuntimeError, "Could not convert to NSString*");
646-
return -1;
647-
}
648-
NSImage* image = [[NSImage alloc] initByReferencingFile: ns_icon_path];
649-
[ns_icon_path release];
650-
if (!image) {
651-
PyErr_SetString(PyExc_RuntimeError, "Could not create NSImage*");
652-
[image release];
653-
return -1;
654-
}
655-
if (!image.valid) {
656-
PyErr_SetString(PyExc_RuntimeError, "Image is not valid");
657-
[image release];
658-
return -1;
641+
@autoreleasepool {
642+
NSString* ns_icon_path = [NSString stringWithUTF8String: icon_path_ptr];
643+
if (!ns_icon_path) {
644+
Py_DECREF(icon_path);
645+
PyErr_SetString(PyExc_RuntimeError, "Could not convert to NSString*");
646+
return -1;
647+
}
648+
NSImage* image = [[[NSImage alloc] initByReferencingFile: ns_icon_path] autorelease];
649+
if (!image) {
650+
PyErr_SetString(PyExc_RuntimeError, "Could not create NSImage*");
651+
return -1;
652+
}
653+
if (!image.valid) {
654+
PyErr_SetString(PyExc_RuntimeError, "Image is not valid");
655+
return -1;
656+
}
657+
NSApplication* app = [NSApplication sharedApplication];
658+
app.applicationIconImage = image;
659659
}
660-
NSApplication* app = [NSApplication sharedApplication];
661-
app.applicationIconImage = image;
662-
[image release];
663660
return 0;
664661
}
665662

0 commit comments

Comments
 (0)