Index: Modules/_sqlite/connection.c =================================================================== --- Modules/_sqlite/connection.c (revision 66831) +++ Modules/_sqlite/connection.c (working copy) @@ -822,6 +822,7 @@ { PyObject* res; PyObject* begin_statement; + char* begin_statement_str; Py_XDECREF(self->isolation_level); @@ -854,12 +855,18 @@ return -1; } - self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2); + begin_statement_str = PyString_AsString(begin_statement); + if (!begin_statement_str) { + Py_DECREF(begin_statement); + return -1; + } + self->begin_statement = PyMem_Malloc(strlen(begin_statement_str) + 2); if (!self->begin_statement) { + Py_DECREF(begin_statement); return -1; } - strcpy(self->begin_statement, PyString_AsString(begin_statement)); + strcpy(self->begin_statement, begin_statement_str); Py_DECREF(begin_statement); } Index: Modules/_sqlite/module.c =================================================================== --- Modules/_sqlite/module.c (revision 66831) +++ Modules/_sqlite/module.c (working copy) @@ -128,12 +128,15 @@ { PyTypeObject* type; PyObject* caster; + int rc; if (!PyArg_ParseTuple(args, "OO", &type, &caster)) { return NULL; } - microprotocols_add(type, (PyObject*)&SQLitePrepareProtocolType, caster); + rc = microprotocols_add(type, (PyObject*)&SQLitePrepareProtocolType, caster); + if (rc == -1) + return NULL; Py_INCREF(Py_None); return Py_None;