Fixed memory leak in lobject

This commit is contained in:
Federico Di Gregorio 2008-12-04 16:58:05 +01:00
parent 4eb295a8ca
commit 5480cf5332
3 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2008-12-04 Federico Di Gregorio <fog@initd.org>
* psycopg/lobject_type.c: fixed memory leak. The patch was kindly
sent from a psycopg user but I wrongly deleted the email so no
kudos (and I had to fix the problem by myself!)
2008-11-25 Federico Di Gregorio <fog@initd.org>
* psycopg/cursor_type.c: integrated patch from Alejandro Dubrovsky.

View File

@ -95,6 +95,7 @@ psyco_lobj_write(lobjectObject *self, PyObject *args)
static PyObject *
psyco_lobj_read(lobjectObject *self, PyObject *args)
{
PyObject *res;
int where, end, size = -1;
char *buffer;
@ -111,13 +112,19 @@ psyco_lobj_read(lobjectObject *self, PyObject *args)
size = end - where;
}
if ((buffer = PyMem_Malloc(size)) == NULL) return NULL;
if ((buffer = PyMem_Malloc(size)) == NULL) {
PyErr_NoMemory();
return NULL;
}
if ((size = lobject_read(self, buffer, size)) < 0) {
PyMem_Free(buffer);
return NULL;
}
return PyString_FromStringAndSize(buffer, size);
res = PyString_FromStringAndSize(buffer, size);
PyMem_Free(buffer);
return res;
}
/* seek method - seek in the lobject */

View File

@ -137,6 +137,11 @@
<File name="tests/test_dates.py" subtype="Code" buildaction="Nothing" />
<File name="tests/test_lobject.py" subtype="Code" buildaction="Nothing" />
<File name="tests/test_quote.py" subtype="Code" buildaction="Nothing" />
<File name="psycopg/cursor_type.c.~1~" subtype="Code" buildaction="Nothing" />
<File name="psycopg/lobject.h" subtype="Code" buildaction="Nothing" />
<File name="psycopg/lobject_int.c" subtype="Code" buildaction="Compile" />
<File name="psycopg/lobject_type.c" subtype="Code" buildaction="Compile" />
<File name="psycopg/typecast_basic.c.old" subtype="Code" buildaction="Nothing" />
</Contents>
<compiler ctype="GccCompiler" />
<MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />