From a3800fa57e9cfb98809ae0d53a5af7f0b27e343f Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Wed, 15 Dec 2021 12:19:04 +0100 Subject: [PATCH] Python: allocate py_req in the http_request_free hook if needed. Makes it possible to mix on_free with other runtimes. --- src/python.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python.c b/src/python.c index 03ee0c1..196e134 100644 --- a/src/python.c +++ b/src/python.c @@ -1331,8 +1331,10 @@ python_runtime_http_request_free(void *addr, struct http_request *req) { PyObject *ret; - if (req->py_req == NULL) - fatal("%s: py_req is NULL", __func__); + if (req->py_req == NULL) { + if ((req->py_req = pyhttp_request_alloc(req)) == NULL) + fatal("%s: pyreq alloc failed", __func__); + } PyErr_Clear(); ret = PyObject_CallFunctionObjArgs(addr, req->py_req, NULL);