fix(misc): fix potential memory errors on macOS
This commit is contained in:
parent
a70d9b6770
commit
81245722b8
|
@ -30,8 +30,6 @@ int32_t clipboard_get_text(char * buffer, int32_t buffer_size) {
|
|||
const char * text = [string UTF8String];
|
||||
strncpy(buffer, text, buffer_size);
|
||||
|
||||
[string release];
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
int32_t info_get_title(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
@autoreleasepool {
|
||||
CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
|
||||
int32_t result = 0;
|
||||
|
||||
|
@ -46,7 +45,6 @@ int32_t info_get_title(char *buffer, int32_t buffer_size)
|
|||
|
||||
CFRelease(windows);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,7 +52,6 @@ int32_t info_get_title(char *buffer, int32_t buffer_size)
|
|||
// Partially taken from: https://stackoverflow.com/questions/480866/get-the-title-of-the-current-active-window-document-in-mac-os-x/23451568#23451568
|
||||
int32_t info_get_title_fallback(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
@autoreleasepool {
|
||||
// Get the process ID of the frontmost application.
|
||||
NSRunningApplication* app = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
pid_t pid = [app processIdentifier];
|
||||
|
@ -94,30 +91,25 @@ int32_t info_get_title_fallback(char *buffer, int32_t buffer_size)
|
|||
return -4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t info_get_exec(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundlePath = [frontApp bundleURL].path;
|
||||
const char * path = [bundlePath UTF8String];
|
||||
|
||||
snprintf(buffer, buffer_size, "%s", path);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t info_get_class(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundleId = frontApp.bundleIdentifier;
|
||||
const char * bundle = [bundleId UTF8String];
|
||||
|
||||
snprintf(buffer, buffer_size, "%s", bundle);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user