mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
MOBI Output: Fix a memory leak and a crash in the palmdoc compression routine
This commit is contained in:
parent
8525faf60c
commit
1ef607f544
@ -151,6 +151,7 @@ cpalmdoc_do_compress(buffer *b, char *output) {
|
|||||||
for (j=0; j < temp.len; j++) *(output++) = (char)temp.data[j];
|
for (j=0; j < temp.len; j++) *(output++) = (char)temp.data[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PyMem_Free(temp.data);
|
||||||
return output - head;
|
return output - head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +169,9 @@ cpalmdoc_compress(PyObject *self, PyObject *args) {
|
|||||||
for (j = 0; j < input_len; j++)
|
for (j = 0; j < input_len; j++)
|
||||||
b.data[j] = (_input[j] < 0) ? _input[j]+256 : _input[j];
|
b.data[j] = (_input[j] < 0) ? _input[j]+256 : _input[j];
|
||||||
b.len = input_len;
|
b.len = input_len;
|
||||||
output = (char *)PyMem_Malloc(sizeof(char) * b.len);
|
// Make the output buffer larger than the input as sometimes
|
||||||
|
// compression results in a larger block
|
||||||
|
output = (char *)PyMem_Malloc(sizeof(char) * (int)(1.25*b.len));
|
||||||
if (output == NULL) return PyErr_NoMemory();
|
if (output == NULL) return PyErr_NoMemory();
|
||||||
j = cpalmdoc_do_compress(&b, output);
|
j = cpalmdoc_do_compress(&b, output);
|
||||||
if ( j == 0) return PyErr_NoMemory();
|
if ( j == 0) return PyErr_NoMemory();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user