{
unsigned int clear = 0, index = 0, incremental = 0;
unsigned int count = 16384 + 1, size = count;
- char *str = malloc(size), *ptr;
+ char *str, *ptr;
PyObject *obj;
int ret;
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwd_list,
&clear, &index, &incremental) ||
- !str )
+ !(str = malloc(size)) )
return NULL;
ret = xc_readconsolering(self->xc_handle, str, &count, clear,
incremental, &index);
- if ( ret < 0 )
+ if ( ret < 0 ) {
+ free(str);
return pyxc_error_to_exception(self->xc_handle);
+ }
- while ( !incremental && count == size )
+ while ( !incremental && count == size && ret >= 0 )
{
size += count - 1;
if ( size < count )
count = size - count;
ret = xc_readconsolering(self->xc_handle, str, &count, clear,
1, &index);
- if ( ret < 0 )
- break;
-
count += str - ptr;
str = ptr;
}