diff --git a/wox.core/plugin/system/app/app_darwin.go b/wox.core/plugin/system/app/app_darwin.go index 1054610f..56dd472a 100644 --- a/wox.core/plugin/system/app/app_darwin.go +++ b/wox.core/plugin/system/app/app_darwin.go @@ -437,7 +437,12 @@ func (a *MacRetriever) getRunningProcesses() (infos []processInfo) { //only show user process continue } - appPath := C.GoString(C.get_process_path(pid)) + cPath := C.get_process_path(pid) + if cPath == nil { + continue + } + appPath := C.GoString(cPath) + C.free(unsafe.Pointer(cPath)) if appPath == "" { continue } diff --git a/wox.core/plugin/system/sys.go b/wox.core/plugin/system/sys.go index 86012800..5315edbb 100644 --- a/wox.core/plugin/system/sys.go +++ b/wox.core/plugin/system/sys.go @@ -140,6 +140,28 @@ func (r *SysPlugin) Init(ctx context.Context, initParams plugin.InitParams) { }, }) + r.commands = append(r.commands, SysCommand{ + Title: "i18n:plugin_sys_performance_memory_profiling", + Icon: plugin.CPUProfileIcon, + Action: func(ctx context.Context, actionContext plugin.ActionContext) { + memoryProfPath := path.Join(util.GetLocation().GetWoxDataDirectory(), "memory.prof") + f, err := os.Create(memoryProfPath) + if err != nil { + util.GetLogger().Info(ctx, "failed to create memory profile file: "+err.Error()) + return + } + + util.GetLogger().Info(ctx, "start memory profile") + profileErr := pprof.WriteHeapProfile(f) + if profileErr != nil { + util.GetLogger().Info(ctx, "failed to start memory profile: "+profileErr.Error()) + return + } + + util.GetLogger().Info(ctx, "memory profile saved to "+memoryProfPath) + }, + }) + r.commands = append(r.commands, SysCommand{ Title: "i18n:plugin_sys_delete_image_cache", Icon: common.NewWoxImageEmoji("🗑️"), diff --git a/wox.core/resource/lang/en_US.json b/wox.core/resource/lang/en_US.json index 6ec8c16e..e11c5153 100644 --- a/wox.core/resource/lang/en_US.json +++ b/wox.core/resource/lang/en_US.json @@ -203,6 +203,7 @@ "plugin_sys_open_wox_settings": "Open Wox Settings", "plugin_sys_open_system_settings": "Open System Settings", "plugin_sys_performance_cpu_profiling": "Performance CPU profiling", + "plugin_sys_performance_memory_profiling": "Performance Memory profiling", "plugin_sys_delete_image_cache": "Delete all image cache", "plugin_sys_open_plugin_settings": "Open %s settings", "plugin_websearch_trigger_keyword": "keyword", diff --git a/wox.core/resource/lang/pt_BR.json b/wox.core/resource/lang/pt_BR.json index fdc90a3f..79ee615f 100644 --- a/wox.core/resource/lang/pt_BR.json +++ b/wox.core/resource/lang/pt_BR.json @@ -201,6 +201,7 @@ "plugin_sys_open_wox_settings": "Abrir configurações do Wox", "plugin_sys_open_system_settings": "Abrir configurações do sistema", "plugin_sys_performance_cpu_profiling": "Perfil de desempenho da CPU", + "plugin_sys_performance_memory_profiling": "Perfil de desempenho de memória", "plugin_sys_delete_image_cache": "Excluir todo o cache de imagem", "plugin_sys_open_plugin_settings": "Abrir configurações do plugin %s", "plugin_websearch_trigger_keyword": "Palavra-chave", diff --git a/wox.core/resource/lang/ru_RU.json b/wox.core/resource/lang/ru_RU.json index ed51ffef..604cb446 100644 --- a/wox.core/resource/lang/ru_RU.json +++ b/wox.core/resource/lang/ru_RU.json @@ -201,6 +201,7 @@ "plugin_sys_open_wox_settings": "Открыть настройки Wox", "plugin_sys_open_system_settings": "Открыть системные настройки", "plugin_sys_performance_cpu_profiling": "Профилирование производительности ЦП", + "plugin_sys_performance_memory_profiling": "Профилирование производительности памяти", "plugin_sys_delete_image_cache": "Удалить весь кэш изображений", "plugin_sys_open_plugin_settings": "Открыть настройки %s", "plugin_websearch_trigger_keyword": "ключевое слово", diff --git a/wox.core/resource/lang/zh_CN.json b/wox.core/resource/lang/zh_CN.json index 47879270..737d1d80 100644 --- a/wox.core/resource/lang/zh_CN.json +++ b/wox.core/resource/lang/zh_CN.json @@ -203,6 +203,7 @@ "plugin_sys_open_wox_settings": "打开Wox设置", "plugin_sys_open_system_settings": "打开系统设置", "plugin_sys_performance_cpu_profiling": "性能 CPU 分析", + "plugin_sys_performance_memory_profiling": "性能 内存 分析", "plugin_sys_delete_image_cache": "删除所有图片缓存", "plugin_sys_open_plugin_settings": "打开 %s 设置", "plugin_websearch_trigger_keyword": "关键字", diff --git a/wox.core/util/ime/ime_darwin.go b/wox.core/util/ime/ime_darwin.go index 4adc1f1f..984bafd9 100644 --- a/wox.core/util/ime/ime_darwin.go +++ b/wox.core/util/ime/ime_darwin.go @@ -29,7 +29,14 @@ func SwitchInputMethodABC() error { errorChan <- err }) - inputMethod := C.GoString(C.getCurrentInputMethod()) + // Fix memory leak: properly free the C-allocated string + cInputMethod := C.getCurrentInputMethod() + if cInputMethod == nil { + errorChan <- errors.New("failed to get current input method") + return + } + inputMethod := C.GoString(cInputMethod) + C.free(unsafe.Pointer(cInputMethod)) if inputMethod == "" { errorChan <- errors.New("failed to get current input method") return diff --git a/wox.core/util/window/window_darwin.go b/wox.core/util/window/window_darwin.go index deea3fdf..d3faba39 100644 --- a/wox.core/util/window/window_darwin.go +++ b/wox.core/util/window/window_darwin.go @@ -37,6 +37,10 @@ func GetActiveWindowIcon() (image.Image, error) { func GetActiveWindowName() string { name := C.getActiveWindowName() + if name == nil { + return "" + } + defer C.free(unsafe.Pointer(name)) return C.GoString(name) } diff --git a/wox.core/util/window/window_windows.go b/wox.core/util/window/window_windows.go index 9b2004f1..5ddc7ea1 100644 --- a/wox.core/util/window/window_windows.go +++ b/wox.core/util/window/window_windows.go @@ -51,11 +51,13 @@ func GetActiveWindowIcon() (image.Image, error) { func GetActiveWindowName() string { cStr := C.getActiveWindowName() + if cStr == nil { + return "" + } + defer C.free(unsafe.Pointer(cStr)) length := C.int(C.strlen(cStr)) bytes := C.GoBytes(unsafe.Pointer(cStr), length) - str := string(bytes) - C.free(unsafe.Pointer(cStr)) - return str + return string(bytes) } func GetActiveWindowPid() int {