Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7dfeb42

Browse files
committed
EnvironmentError__init__(): The two case clauses were missing
`break's. This first missing break caused a memory leak when case 3 fell through case 2 in the following example: import os os.chmod('/missing', 0600)
1 parent 4288c80 commit 7dfeb42

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Python/exceptions.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,10 @@ EnvironmentError__init__(PyObject* self, PyObject* args)
440440

441441
switch (PySequence_Length(args)) {
442442
case 3:
443-
/* open() errors give third argument which is the filename. But so
444-
* common in-place unpacking doesn't break, e.g.:
443+
/* Where a function has a single filename, such as open() or some
444+
* of the os module functions, PyErr_SetFromErrnoWithFilename() is
445+
* called, giving a third argument which is the filename. But, so
446+
* that old code using in-place unpacking doesn't break, e.g.:
445447
*
446448
* except IOError, (errno, strerror):
447449
*
@@ -465,9 +467,12 @@ EnvironmentError__init__(PyObject* self, PyObject* args)
465467
subslice = PySequence_GetSlice(args, 0, 2);
466468
if (!subslice || PyObject_SetAttrString(self, "args", subslice))
467469
goto finally;
470+
break;
468471

469472
case 2:
470-
/* common case: PyErr_SetFromErrno() */
473+
/* Used when PyErr_SetFromErrno() is called and no filename
474+
* argument is given.
475+
*/
471476
item0 = PySequence_GetItem(args, 0);
472477
item1 = PySequence_GetItem(args, 1);
473478
if (!item0 || !item1)
@@ -478,6 +483,7 @@ EnvironmentError__init__(PyObject* self, PyObject* args)
478483
{
479484
goto finally;
480485
}
486+
break;
481487
}
482488

483489
Py_INCREF(Py_None);

0 commit comments

Comments
 (0)