This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: readline.replace_history_item leaks memory.
Type: resource usage Stage: resolved
Components: Extension Modules Versions: Python 3.1, Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: mark.dickinson
Priority: normal Keywords: patch

Created on 2010-08-01 18:13 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue9450.patch mark.dickinson, 2010-08-01 19:07
Messages (6)
msg112363 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-01 18:13
Some functions in the readline module appear to leak memory;  readline.replace_history_item is one of these:

Test code:

import readline
readline.add_history("first line")
readline.add_history("second line")
while True:
    readline.replace_history_item(0, "replaced item")

This is on OS X 10.6.4, with a 64-bit debug build of Python, and the readline module linked against a local build of GNU readline version 6.1.
msg112368 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-01 19:07
This patch fixes the leaks in replace_history_item, remove_history_item (similar), and get_current_history_length.

I'm not sure which version of the GNU history library introduced free_history_entry (which is used by this patch).  I also haven't checked whether it's available in libedit (used on OS X).
msg112369 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-01 19:14
See also issue #8065.
msg112376 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-01 19:48
It turns out that free_history_entry is new in GNU Readline 5.0.  It doesn't exist in libedit.
msg112624 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-03 16:20
Leaks in replace_history_item and remove_history_item fixed in r83667 (py3k), r83668 (release31-maint) and r83669 (release27-maint).
msg112632 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-03 16:58
The other leaks have now been fixed too; see issue 8065 for details.
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53695
2014-10-08 19:23:57terry.reedylinkissue8065 superseder
2010-08-03 16:58:59mark.dickinsonsetstatus: open -> closed
messages: + msg112632

assignee: mark.dickinson
resolution: fixed
stage: needs patch -> resolved
2010-08-03 16:20:15mark.dickinsonsetmessages: + msg112624
versions: + Python 3.1, Python 2.7
2010-08-01 19:48:05mark.dickinsonsetmessages: + msg112376
2010-08-01 19:14:47mark.dickinsonsetmessages: + msg112369
2010-08-01 19:07:36mark.dickinsonsetfiles: + issue9450.patch
keywords: + patch
messages: + msg112368
2010-08-01 18:13:30mark.dickinsoncreate