This commit is contained in:
Kovid Goyal 2026-10-16 12:57:07 +05:30
parent cd1dc74270
commit 7e2a3cf81f
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 16 deletions

View file

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -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 *