forked from fedora-python/python26
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython-2.6.6-readline-introduce-py-free-history-entry.patch
71 lines (68 loc) · 2 KB
/
python-2.6.6-readline-introduce-py-free-history-entry.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff -up Python-2.6.6/Misc/NEWS.63e1d0dc44ee Python-2.6.6/Misc/NEWS
diff -up Python-2.6.6/Modules/readline.c.63e1d0dc44ee Python-2.6.6/Modules/readline.c
--- Python-2.6.6/Modules/readline.c.63e1d0dc44ee 2010-05-09 11:15:40.000000000 -0400
+++ Python-2.6.6/Modules/readline.c 2011-06-30 19:14:03.133626137 -0400
@@ -355,6 +355,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)
{
@@ -376,12 +408,7 @@ py_remove_history(PyObject *self, PyObje
return NULL;
}
/* free memory allocated for the history entry */
- if (entry->line)
- free(entry->line);
- if (entry->data)
- free(entry->data);
- free(entry);
-
+ _py_free_history_entry(entry);
Py_RETURN_NONE;
}
@@ -413,12 +440,7 @@ py_replace_history(PyObject *self, PyObj
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);
-
+ _py_free_history_entry(old_entry);
Py_RETURN_NONE;
}