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

Skip to content

Commit 5751258

Browse files
committed
fix error handling of PyNumber_InPlaceOr #6000
1 parent ff0e500 commit 5751258

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

Python/symtable.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
658658
{
659659
PyObject *name, *v, *local = NULL, *scopes = NULL, *newbound = NULL;
660660
PyObject *newglobal = NULL, *newfree = NULL, *allfree = NULL;
661+
PyObject *temp;
661662
int i, success = 0;
662663
Py_ssize_t pos = 0;
663664

@@ -696,14 +697,16 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
696697
*/
697698
if (ste->ste_type == ClassBlock) {
698699
/* Pass down known globals */
699-
if (!PyNumber_InPlaceOr(newglobal, global))
700+
temp = PyNumber_InPlaceOr(newglobal, global);
701+
if (!temp)
700702
goto error;
701-
Py_DECREF(newglobal);
703+
Py_DECREF(temp);
702704
/* Pass down previously bound symbols */
703705
if (bound) {
704-
if (!PyNumber_InPlaceOr(newbound, bound))
706+
temp = PyNumber_InPlaceOr(newbound, bound);
707+
if (!temp)
705708
goto error;
706-
Py_DECREF(newbound);
709+
Py_DECREF(temp);
707710
}
708711
}
709712

@@ -718,20 +721,23 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
718721
if (ste->ste_type != ClassBlock) {
719722
/* Add function locals to bound set */
720723
if (ste->ste_type == FunctionBlock) {
721-
if (!PyNumber_InPlaceOr(newbound, local))
724+
temp = PyNumber_InPlaceOr(newbound, local);
725+
if (!temp)
722726
goto error;
723-
Py_DECREF(newbound);
727+
Py_DECREF(temp);
724728
}
725729
/* Pass down previously bound symbols */
726730
if (bound) {
727-
if (!PyNumber_InPlaceOr(newbound, bound))
731+
temp = PyNumber_InPlaceOr(newbound, bound);
732+
if (!temp)
728733
goto error;
729-
Py_DECREF(newbound);
734+
Py_DECREF(temp);
730735
}
731736
/* Pass down known globals */
732-
if (!PyNumber_InPlaceOr(newglobal, global))
737+
temp = PyNumber_InPlaceOr(newglobal, global);
738+
if (!temp)
733739
goto error;
734-
Py_DECREF(newglobal);
740+
Py_DECREF(temp);
735741
}
736742
else {
737743
/* Special-case __class__ */
@@ -764,9 +770,10 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
764770
ste->ste_child_free = 1;
765771
}
766772

767-
if (PyNumber_InPlaceOr(newfree, allfree) < 0)
773+
temp = PyNumber_InPlaceOr(newfree, allfree);
774+
if (!temp)
768775
goto error;
769-
Py_DECREF(newfree);
776+
Py_DECREF(temp);
770777

771778
/* Check if any local variables must be converted to cell variables */
772779
if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree,
@@ -782,9 +789,10 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
782789
if (!check_unoptimized(ste))
783790
goto error;
784791

785-
if (!PyNumber_InPlaceOr(free, newfree))
792+
temp = PyNumber_InPlaceOr(free, newfree);
793+
if (!temp)
786794
goto error;
787-
Py_DECREF(free);
795+
Py_DECREF(temp);
788796
success = 1;
789797
error:
790798
Py_XDECREF(scopes);
@@ -803,6 +811,7 @@ analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
803811
PyObject *global, PyObject* child_free)
804812
{
805813
PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL;
814+
PyObject *temp;
806815

807816
/* Copy the bound and global dictionaries.
808817
@@ -823,9 +832,10 @@ analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
823832

824833
if (!analyze_block(entry, temp_bound, temp_free, temp_global))
825834
goto error;
826-
if (PyNumber_InPlaceOr(child_free, temp_free) < 0)
835+
temp = PyNumber_InPlaceOr(child_free, temp_free);
836+
if (!temp)
827837
goto error;
828-
Py_DECREF(child_free);
838+
Py_DECREF(temp);
829839
Py_DECREF(temp_bound);
830840
Py_DECREF(temp_free);
831841
Py_DECREF(temp_global);

0 commit comments

Comments
 (0)