Python module Doc_setattr: miscplaced DECREF caused crashes
This commit is contained in:
parent
e711f1e1a9
commit
1796ba1a2e
@ -609,7 +609,6 @@ Doc_getattro(recoll_DocObject *self, PyObject *nameobj)
|
|||||||
static int
|
static int
|
||||||
Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
||||||
{
|
{
|
||||||
LOGDEB0(("Doc_setattr: doc %p\n", self->doc));
|
|
||||||
if (self->doc == 0 || the_docs.find(self->doc) == the_docs.end()) {
|
if (self->doc == 0 || the_docs.find(self->doc) == the_docs.end()) {
|
||||||
PyErr_SetString(PyExc_AttributeError, "doc??");
|
PyErr_SetString(PyExc_AttributeError, "doc??");
|
||||||
return -1;
|
return -1;
|
||||||
@ -619,24 +618,22 @@ Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
|||||||
"Configuration not initialized");
|
"Configuration not initialized");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION < 3
|
|
||||||
if (PyString_Check(value)) {
|
|
||||||
value = PyUnicode_FromObject(value);
|
|
||||||
if (value == 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!PyUnicode_Check(value)) {
|
|
||||||
PyErr_SetString(PyExc_AttributeError, "value not str/unicode??");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (name == 0) {
|
if (name == 0) {
|
||||||
PyErr_SetString(PyExc_AttributeError, "name??");
|
PyErr_SetString(PyExc_AttributeError, "name??");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PyBytes_Check(value)) {
|
||||||
|
value = PyUnicode_FromEncodedObject(value, "UTF-8", "strict");
|
||||||
|
if (value == 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PyUnicode_Check(value)) {
|
||||||
|
PyErr_SetString(PyExc_AttributeError, "value not unicode??");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject* putf8 = PyUnicode_AsUTF8String(value);
|
PyObject* putf8 = PyUnicode_AsUTF8String(value);
|
||||||
if (putf8 == 0) {
|
if (putf8 == 0) {
|
||||||
LOGERR(("Doc_setmeta: encoding to utf8 failed\n"));
|
LOGERR(("Doc_setmeta: encoding to utf8 failed\n"));
|
||||||
@ -644,10 +641,11 @@ Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char* uvalue = PyBytes_AsString(putf8);
|
char* uvalue = PyBytes_AsString(putf8);
|
||||||
Py_DECREF(putf8);
|
|
||||||
string key = rclconfig->fieldQCanon(string(name));
|
string key = rclconfig->fieldQCanon(string(name));
|
||||||
|
|
||||||
LOGDEB0(("Doc_setattr: [%s] (%s) -> [%s]\n", key.c_str(), name, uvalue));
|
LOGDEB0(("Doc_setattr: doc %p [%s] (%s) -> [%s]\n",
|
||||||
|
self->doc, key.c_str(), name, uvalue));
|
||||||
|
|
||||||
// We set the value in the meta array in all cases. Good idea ? or do it
|
// We set the value in the meta array in all cases. Good idea ? or do it
|
||||||
// only for fields without a dedicated Doc:: entry?
|
// only for fields without a dedicated Doc:: entry?
|
||||||
self->doc->meta[key] = uvalue;
|
self->doc->meta[key] = uvalue;
|
||||||
@ -701,6 +699,7 @@ Doc_setattr(recoll_DocObject *self, char *name, PyObject *value)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(putf8);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user