Skip to content

Commit 24fc7db

Browse files
committed
macos, fix #2658: don't double-free in case of environ() error
1 parent f33513e commit 24fc7db

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

psutil/arch/osx/proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
11261126
goto error;
11271127
}
11281128

1129-
while (*arg_ptr != '\0' && arg_ptr < arg_end) {
1129+
while (arg_ptr < arg_end && *arg_ptr != '\0') {
11301130
char *s = memchr(arg_ptr + 1, '\0', arg_end - arg_ptr);
11311131
if (s == NULL)
11321132
break;
@@ -1158,6 +1158,6 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
11581158
if (procargs != NULL)
11591159
free(procargs);
11601160
if (procenv != NULL)
1161-
free(procargs);
1161+
free(procenv);
11621162
return NULL;
11631163
}

0 commit comments

Comments
 (0)