Mercurial > cpython-lru_cache-weakref
diff Modules/_sqlite/connection.c @ 49469:69ea12db9b28 2.5
Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
module.
| author | Gerhard Häring <gh@ghaering.de> |
|---|---|
| date | Wed, 08 Oct 2008 08:45:16 +0000 |
| parents | 408d2a596f99 |
| children | 787b969d37f0 |
line wrap: on
line diff
--- a/Modules/_sqlite/connection.c Tue Sep 30 17:47:50 2008 +0000 +++ b/Modules/_sqlite/connection.c Wed Oct 08 08:45:16 2008 +0000 @@ -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); }
