~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to psycopg/lobject_type.c

  • Committer: Federico Di Gregorio
  • Date: 2008-12-04 15:58:05 UTC
  • Revision ID: fog@initd.org-20081204155805-s0jah84m4ydnggl5
Fixed memory leak in lobject

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
static PyObject *
96
96
psyco_lobj_read(lobjectObject *self, PyObject *args)
97
97
{
 
98
    PyObject *res;
98
99
    int where, end, size = -1;
99
100
    char *buffer;
100
101
 
111
112
        size = end - where;
112
113
    }
113
114
 
114
 
    if ((buffer = PyMem_Malloc(size)) == NULL) return NULL;
 
115
    if ((buffer = PyMem_Malloc(size)) == NULL) {
 
116
        PyErr_NoMemory();
 
117
        return NULL;
 
118
    }
115
119
    if ((size = lobject_read(self, buffer, size)) < 0) {
116
120
        PyMem_Free(buffer);
117
121
        return NULL;
118
122
    }
119
123
 
120
 
    return PyString_FromStringAndSize(buffer, size);
 
124
    res = PyString_FromStringAndSize(buffer, size);
 
125
    PyMem_Free(buffer);
 
126
    
 
127
    return res;
121
128
}
122
129
 
123
130
/* seek method - seek in the lobject */