From d82322227584159a19a409d9619baf624d3d9c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Mon, 24 Oct 2011 12:59:35 +0000 Subject: [PATCH] Fix a segfault within the Python interpreter. The segfault happens on some rare _({}) usages for error messages in COMAR scripts. Incrementing reference on the returned dictionary value fixed the problem at least on my setup. --- comar/src/script.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/comar/src/script.c b/comar/src/script.c index 62a76f7..21998f9 100644 --- a/comar/src/script.c +++ b/comar/src/script.c @@ -332,6 +332,7 @@ static PyObject * c_i18n(PyObject *self, PyObject *args) { PyObject *py_dict; + PyObject *py_value; if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &py_dict)) { return NULL; @@ -343,10 +344,12 @@ c_i18n(PyObject *self, PyObject *args) } if (PyDict_Contains(py_dict, py_lang)) { - return PyDict_GetItem(py_dict, py_lang); + py_value = PyDict_GetItem(py_dict, py_lang); + Py_INCREF(py_value); + return py_value; } else { - PyErr_Format(PyExc_COMAR_Script, "Script is lack of default ('en') locale string."); + PyErr_Format(PyExc_COMAR_Script, "'en' locale string should be provided by default in COMAR scripts."); return NULL; } } -- 2.18.1