Index: Modules/readline.c =================================================================== --- Modules/readline.c (revision 83416) +++ Modules/readline.c (working copy) @@ -383,6 +383,7 @@ { int entry_number; HIST_ENTRY *entry; + histdata_t data; if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) return NULL; @@ -399,11 +400,8 @@ return NULL; } /* free memory allocated for the history entry */ - if (entry->line) - free(entry->line); - if (entry->data) - free(entry->data); - free(entry); + data = free_history_entry(entry); + free(data); Py_RETURN_NONE; } @@ -418,6 +416,7 @@ int entry_number; char *line; HIST_ENTRY *old_entry; + histdata_t data; if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, &line)) { @@ -436,11 +435,8 @@ return NULL; } /* free memory allocated for the old history entry */ - if (old_entry->line) - free(old_entry->line); - if (old_entry->data) - free(old_entry->data); - free(old_entry); + data = free_history_entry(old_entry); + free(data); Py_RETURN_NONE; } @@ -531,8 +527,10 @@ * difference. */ HISTORY_STATE *hist_st; + int length; hist_st = history_get_history_state(); - + length = hist_st->length; + free(hist_st); idx --; /* @@ -540,7 +538,7 @@ * the index is out of range, therefore * test for that and fail gracefully. */ - if (idx < 0 || idx >= hist_st->length) { + if (idx < 0 || idx >= length) { Py_RETURN_NONE; } } @@ -563,9 +561,12 @@ get_current_history_length(PyObject *self, PyObject *noarg) { HISTORY_STATE *hist_st; + int length; hist_st = history_get_history_state(); - return PyLong_FromLong(hist_st ? (long) hist_st->length : (long) 0); + length = hist_st->length; + free(hist_st); + return PyLong_FromLong((long)length); } PyDoc_STRVAR(doc_get_current_history_length,