diff options
author | Barry Warsaw <barry@python.org> | 1999-02-01 17:09:00 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1999-02-01 17:09:00 (GMT) |
commit | 6aa42579be55f82141b183d547f71ce10303677a (patch) | |
tree | 40747e86ef615d6bd45d48be825be45501799133 /Modules | |
parent | a61f4ac14d764dc4f91c5a86f170a597de4c3a73 (diff) | |
download | cpython-6aa42579be55f82141b183d547f71ce10303677a.zip cpython-6aa42579be55f82141b183d547f71ce10303677a.tar.gz cpython-6aa42579be55f82141b183d547f71ce10303677a.tar.bz2 |
PyPcre_expand(): Fixed two memory leaks, where a PyString_FromString()
was appended to a list. Lists are reference count neutral, so the
string must be DECREF'd. Also added some checks for the return value
of PyList_Append().
Note: there are still some memory problems reported by Purify (I get
two Array Bounds Reads still and an Unitialized Memory Read). Also,
in scanning the code, there appears to be some potential problems
where return values aren't checked. To much to attack now though.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/pcremodule.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/Modules/pcremodule.c b/Modules/pcremodule.c index fa98696..3b61697 100644 --- a/Modules/pcremodule.c +++ b/Modules/pcremodule.c @@ -489,8 +489,19 @@ PyPcre_expand(self, args) if (start!=i) { - PyList_Append(results, - PyString_FromStringAndSize((char *)repl+start, i-start)); + int status; + PyObject *s = PyString_FromStringAndSize( + (char *)repl+start, i-start); + if (s == NULL) { + Py_DECREF(results); + return NULL; + } + status = PyList_Append(results, s); + Py_DECREF(s); + if (status < 0) { + Py_DECREF(results); + return NULL; + } total_len += i-start; } i++; @@ -574,7 +585,19 @@ PyPcre_expand(self, args) if (start!=i) { - PyList_Append(results, PyString_FromStringAndSize((char *)repl+start, i-start)); + int status; + PyObject *s = PyString_FromStringAndSize((char *)repl+start, + i-start); + if (s == NULL) { + Py_DECREF(results); + return NULL; + } + status = PyList_Append(results, s); + Py_DECREF(s); + if (status < 0) { + Py_DECREF(results); + return NULL; + } total_len += i-start; } |