summaryrefslogtreecommitdiff
path: root/Modules/cStringIO.c
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2007-04-25 00:10:50 +0000
committerKristján Valur Jónsson <kristjan@ccpgames.com>2007-04-25 00:10:50 +0000
commit17b8e97e2e2c24322d45c33308212e0d6c32d934 (patch)
treeb29361f28ad72a27c5d235e75a6340ebf03209d4 /Modules/cStringIO.c
parente133a95d1c6c6b28afe66dc0118282fe0d1073f1 (diff)
downloadcpython-git-17b8e97e2e2c24322d45c33308212e0d6c32d934.tar.gz
Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Diffstat (limited to 'Modules/cStringIO.c')
-rw-r--r--Modules/cStringIO.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 3f762b09fb..208569610a 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -349,13 +349,17 @@ O_seek(Oobject *self, PyObject *args) {
}
if (position > self->buf_size) {
+ char *newbuf;
self->buf_size*=2;
if (self->buf_size <= position) self->buf_size=position+1;
- self->buf = (char*) realloc(self->buf,self->buf_size);
- if (!self->buf) {
+ newbuf = (char*) realloc(self->buf,self->buf_size);
+ if (!newbuf) {
+ free(self->buf);
+ self->buf = 0;
self->buf_size=self->pos=0;
return PyErr_NoMemory();
}
+ self->buf = newbuf;
}
else if (position < 0) position=0;
@@ -376,6 +380,7 @@ static int
O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
Py_ssize_t newl;
Oobject *oself;
+ char *newbuf;
if (!IO__opencheck(IOOOBJECT(self))) return -1;
oself = (Oobject *)self;
@@ -387,12 +392,15 @@ O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
assert(newl + 1 < INT_MAX);
oself->buf_size = (int)(newl+1);
}
- oself->buf = (char*)realloc(oself->buf, oself->buf_size);
- if (!oself->buf) {
+ newbuf = (char*)realloc(oself->buf, oself->buf_size);
+ if (!newbuf) {
PyErr_SetString(PyExc_MemoryError,"out of memory");
+ free(oself->buf);
+ oself->buf = 0;
oself->buf_size = oself->pos = 0;
return -1;
}
+ oself->buf = newbuf;
}
memcpy(oself->buf+oself->pos,c,l);