From b12e8a69693b339012a5b0076143d81cb2fc4079 Mon Sep 17 00:00:00 2001 From: krangelov Date: Mon, 27 Sep 2021 05:30:00 +0200 Subject: [PATCH] fix Expr_call --- src/runtime/python/expr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/runtime/python/expr.c b/src/runtime/python/expr.c index eaceadcc9..1e02682ee 100644 --- a/src/runtime/python/expr.c +++ b/src/runtime/python/expr.c @@ -216,12 +216,21 @@ Expr_call(ExprObject* self, PyObject* args, PyObject* kw) size_t n_args = PyTuple_Size(args); for (size_t i = 0; i < n_args; i++) { PyObject* arg = PyTuple_GetItem(args, i); - if (arg->ob_type != &pgf_ExprType) { + if (arg == NULL) { + Py_DECREF(res); + return NULL; + } + if (!PyObject_TypeCheck(arg, &pgf_ExprType)) { + Py_DECREF(res); PyErr_SetString(PyExc_TypeError, "the arguments must be expressions"); return NULL; } ExprAppObject *pyexpr = (ExprAppObject *)pgf_ExprAppType.tp_alloc(&pgf_ExprAppType, 0); + if (pyexpr == NULL) { + Py_DECREF(res); + return NULL; + } pyexpr->fun = res; pyexpr->arg = (ExprObject *)arg; Py_INCREF(arg); res = (ExprObject *) pyexpr;