mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Fix a memory leak in the spell checker
This commit is contained in:
parent
edcd88b346
commit
313b2096c7
@ -58,16 +58,17 @@ dealloc(Dictionary *self) {
|
|||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
recognized(Dictionary *self, PyObject *args) {
|
recognized(Dictionary *self, PyObject *args) {
|
||||||
char *word;
|
char *word = NULL;
|
||||||
if (!PyArg_ParseTuple(args, "es", self->encoding, &word)) return NULL;
|
if (!PyArg_ParseTuple(args, "es", self->encoding, &word)) return NULL;
|
||||||
|
|
||||||
if (self->handle->spell(word) == 0) Py_RETURN_FALSE;
|
if (self->handle->spell(word) == 0) { PyMem_Free(word); Py_RETURN_FALSE;}
|
||||||
|
PyMem_Free(word);
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
suggest(Dictionary *self, PyObject *args) {
|
suggest(Dictionary *self, PyObject *args) {
|
||||||
char *word, **slist = NULL;
|
char *word = NULL, **slist = NULL;
|
||||||
int i, num_slist;
|
int i, num_slist;
|
||||||
PyObject *ans, *temp;
|
PyObject *ans, *temp;
|
||||||
|
|
||||||
@ -85,24 +86,27 @@ suggest(Dictionary *self, PyObject *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (slist != NULL) self->handle->free_list(&slist, num_slist);
|
if (slist != NULL) self->handle->free_list(&slist, num_slist);
|
||||||
|
PyMem_Free(word);
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
add(Dictionary *self, PyObject *args) {
|
add(Dictionary *self, PyObject *args) {
|
||||||
char *word;
|
char *word = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "es", self->encoding, &word)) return NULL;
|
if (!PyArg_ParseTuple(args, "es", self->encoding, &word)) return NULL;
|
||||||
if (self->handle->add(word) == 0) Py_RETURN_TRUE;
|
if (self->handle->add(word) == 0) { PyMem_Free(word); Py_RETURN_TRUE; }
|
||||||
|
PyMem_Free(word);
|
||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
remove_word(Dictionary *self, PyObject *args) {
|
remove_word(Dictionary *self, PyObject *args) {
|
||||||
char *word;
|
char *word = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "es", self->encoding, &word)) return NULL;
|
if (!PyArg_ParseTuple(args, "es", self->encoding, &word)) return NULL;
|
||||||
if (self->handle->remove(word) == 0) Py_RETURN_TRUE;
|
if (self->handle->remove(word) == 0) { PyMem_Free(word); Py_RETURN_TRUE; }
|
||||||
|
PyMem_Free(word);
|
||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user