summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-08-03 16:18:39 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-08-03 16:18:39 (GMT)
commit4ee9853028429563d72c214ad1a2cda27ace6625 (patch)
treef92ae32ba77cd20d25914b492bde622399d84d30 /Modules
parent5ebb3beb9b62555e96c1bfdc96609819c68e3ae0 (diff)
downloadcpython-4ee9853028429563d72c214ad1a2cda27ace6625.zip
cpython-4ee9853028429563d72c214ad1a2cda27ace6625.tar.gz
cpython-4ee9853028429563d72c214ad1a2cda27ace6625.tar.bz2
Merged revisions 83667 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83667 | mark.dickinson | 2010-08-03 17:08:16 +0100 (Tue, 03 Aug 2010) | 2 lines Issue #9450: Fix memory leaks in readline.remove/replace_history_entry. ........
Diffstat (limited to 'Modules')
-rw-r--r--Modules/readline.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index 4a5d089..fb6d3f9 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -356,6 +356,38 @@ PyDoc_STRVAR(doc_set_completer_delims,
"set_completer_delims(string) -> None\n\
set the readline word delimiters for tab-completion");
+/* _py_free_history_entry: Utility function to free a history entry. */
+
+#if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0500
+
+/* Readline version >= 5.0 introduced a timestamp field into the history entry
+ structure; this needs to be freed to avoid a memory leak. This version of
+ readline also introduced the handy 'free_history_entry' function, which
+ takes care of the timestamp. */
+
+static void
+_py_free_history_entry(HIST_ENTRY *entry)
+{
+ histdata_t data = free_history_entry(entry);
+ free(data);
+}
+
+#else
+
+/* No free_history_entry function; free everything manually. */
+
+static void
+_py_free_history_entry(HIST_ENTRY *entry)
+{
+ if (entry->line)
+ free((void *)entry->line);
+ if (entry->data)
+ free(entry->data);
+ free(entry);
+}
+
+#endif
+
static PyObject *
py_remove_history(PyObject *self, PyObject *args)
{
@@ -377,12 +409,7 @@ py_remove_history(PyObject *self, PyObject *args)
return NULL;
}
/* free memory allocated for the history entry */
- if (entry->line)
- free((void *)entry->line);
- if (entry->data)
- free(entry->data);
- free(entry);
-
+ _py_free_history_entry(entry);
Py_RETURN_NONE;
}
@@ -414,12 +441,7 @@ py_replace_history(PyObject *self, PyObject *args)
return NULL;
}
/* free memory allocated for the old history entry */
- if (old_entry->line)
- free((void *)old_entry->line);
- if (old_entry->data)
- free(old_entry->data);
- free(old_entry);
-
+ _py_free_history_entry(old_entry);
Py_RETURN_NONE;
}