diff --git a/docs/changelog.rst b/docs/changelog.rst index 66ec65a7c..a34149228 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -482,6 +482,9 @@ Detailed list of changes :option:`kitten @ set-colors --reset` not restoring them and not resetting all windows and the configured colors when used from the command line +- macOS: Fix a memory leak when getting the list of all processes, for + example, when querying the memory used by child processes (:iss:`10673`) + 0.49.2 [2026-10-01] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/macos_process_info.c b/kitty/macos_process_info.c index 1f6854f6c..dd6fd9e4b 100644 --- a/kitty/macos_process_info.c +++ b/kitty/macos_process_info.c @@ -71,29 +71,19 @@ get_all_processes(PyObject *self UNUSED, PyObject *args UNUSED) { pid_t num = proc_listallpids(NULL, 0); if (num <= 0) return PyTuple_New(0); size_t sz = sizeof(pid_t) * num * 2; - pid_t *buf = malloc(sz); + RAII_ALLOC(pid_t, buf, malloc(sz)); if (!buf) return PyErr_NoMemory(); num = proc_listallpids(buf, sz); - if (num <= 0) { - free(buf); - return PyTuple_New(0); - } - PyObject *ans = PyTuple_New(num); - if (!ans) { - free(buf); - return NULL; - } + if (num <= 0) return PyTuple_New(0); + RAII_PyObject(ans, PyTuple_New(num)); + if (!ans) return NULL; for (pid_t i = 0; i < num; i++) { long long pid = buf[i]; PyObject *t = PyLong_FromLongLong(pid); - if (!t) { - free(buf); - Py_CLEAR(ans); - return NULL; - } + if (!t) return NULL; PyTuple_SET_ITEM(ans, i, t); } - return ans; + return Py_NewRef(ans); } static PyObject *