File tree Expand file tree Collapse file tree 1 file changed +18
-21
lines changed Expand file tree Collapse file tree 1 file changed +18
-21
lines changed Original file line number Diff line number Diff line change 1
- #include < objc/NSObjCRuntime.h>
2
1
#define PY_SSIZE_T_CLEAN
3
2
#include < Cocoa/Cocoa.h>
4
3
#include < ApplicationServices/ApplicationServices.h>
@@ -639,27 +638,25 @@ int set_icon(PyObject* icon_path) {
639
638
Py_DECREF (icon_path);
640
639
return -1 ;
641
640
}
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;
659
659
}
660
- NSApplication * app = [NSApplication sharedApplication ];
661
- app.applicationIconImage = image;
662
- [image release ];
663
660
return 0 ;
664
661
}
665
662
You can’t perform that action at this time.
0 commit comments