Skip to content

Commit

Permalink
Properly handle memory allocation errors in hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron authored and Sekenre committed Nov 28, 2022
1 parent 892698e commit 3c1d3bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/tags.c
Expand Up @@ -109,8 +109,7 @@ CBORTag_richcompare(PyObject *aobj, PyObject *bobj, int op)
} else {
a = (CBORTagObject *)aobj;
b = (CBORTagObject *)bobj;

if (a == b) {
if (a == b) {
// Special case: both are the same object
switch (op) {
case Py_EQ: case Py_LE: case Py_GE: ret = Py_True; break;
Expand Down Expand Up @@ -143,7 +142,12 @@ static Py_hash_t
CBORTag_hash(CBORTagObject *self)
{
PyObject *tmp = Py_BuildValue("(iO)", self->tag, self->value);
if(!tmp){
PyErr_NoMemory();
return -1;
}
Py_hash_t ret = PyObject_Hash(tmp);
Py_CLEAR(self->value);
Py_CLEAR(tmp);
return ret;
}
Expand Down

0 comments on commit 3c1d3bf

Please sign in to comment.