[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-readline] Feature request for deinitialization function
From: |
Ondřej Adamovský |
Subject: |
[Bug-readline] Feature request for deinitialization function |
Date: |
Thu, 26 Jan 2012 15:54:40 +0100 |
User-agent: |
Opera Mail/11.61 (Linux) |
Hello,
I would like the Readline library to contain a function which would free
all internal allocated data. Without this function, debugging of a program
using readline library with Valgrind is much harder.
Currently, I am using Readline 5.2, but as mentioned here
http://lists.gnu.org/archive/html/bug-readline/2010-05/msg00003.html, same
problems apply to version 6.1 too. Due to some readline internal state
initialization, Valgrind reports some memory still reachable at the end of
program execution (see below).
I have to disagree with the response to the bug-report mentioned above:
http://lists.gnu.org/archive/html/bug-readline/2010-05/msg00004.html .
Allocated data still reachable at the end of execution are the first
indication of a memory leak. When some allocated data are still reachable,
it does not mean it is supposed to be reachable, therefore it is the best
practice to create programs without any allocated data reachable at the
end of execution. Without the deinitialization function, a programmer
checking his work using Valgrind (or probably any other similar tool) is
forced to repeatedly closely examine the Valgrind output (fortunately,
Valgrind has the ability to suppress user defined leaks, but still, at
least the number of still reachable bytes is rendered useless by
uncontrollable influence of readline)
Allocated data still reachable at the end of execution of released program
may be OK, when we know there are no leaks. The same behavior is very bad
for a library, because it pollutes all programs that use it. Therefore, I
think, readline library would benefit from deinitialization function.
Also, its implementation should not be too complicated.
Illustration of Valgrind memcheck output (with --leak-check=full):
==12156== malloc/free: in use at exit: 98,152 bytes in 165 blocks.
==12156== malloc/free: 275,445 allocs, 275,280 frees, 209,009,153 bytes
allocated.
==12156==
==12156== searching for pointers to 165 not-freed blocks.
==12156== checked 477,848 bytes.
==12156==
==12156== 14 bytes in 1 blocks are still reachable in loss record 1 of 11
==12156== at 0x4C22741: realloc (vg_replace_malloc.c:429)
==12156== by 0x6F1744A: _nc_doalloc (in /lib/libncurses.so.5.7)
==12156== by 0x6F1ACA8: tparm (in /lib/libncurses.so.5.7)
==12156== by 0x6F1E010: _nc_trim_sgr0 (in /lib/libncurses.so.5.7)
==12156== by 0x6F19DC8: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 14 bytes in 2 blocks are still reachable in loss record 2 of 11
==12156== at 0x4C2260E: malloc (vg_replace_malloc.c:207)
==12156== by 0x69F9DF1: strdup (strdup.c:43)
==12156== by 0x6F1E071: _nc_trim_sgr0 (in /lib/libncurses.so.5.7)
==12156== by 0x6F19DC8: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 23 bytes in 1 blocks are still reachable in loss record 3 of 11
==12156== at 0x4C2260E: malloc (vg_replace_malloc.c:207)
==12156== by 0x6F176F3: _nc_home_terminfo (in /lib/libncurses.so.5.7)
==12156== by 0x6F17374: _nc_next_db (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D7FB: _nc_read_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F18FF5: (within /lib/libncurses.so.5.7)
==12156== by 0x6F194BF: _nc_setupterm (in /lib/libncurses.so.5.7)
==12156== by 0x6F19C49: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 44 bytes in 1 blocks are still reachable in loss record 4 of 11
==12156== at 0x4C203E4: calloc (vg_replace_malloc.c:397)
==12156== by 0x6F1D02F: _nc_read_termtype (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D6D2: _nc_read_file_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D860: _nc_read_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F18FF5: (within /lib/libncurses.so.5.7)
==12156== by 0x6F194BF: _nc_setupterm (in /lib/libncurses.so.5.7)
==12156== by 0x6F19C49: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 78 bytes in 1 blocks are still reachable in loss record 5 of 11
==12156== at 0x4C203E4: calloc (vg_replace_malloc.c:397)
==12156== by 0x6F1D09F: _nc_read_termtype (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D6D2: _nc_read_file_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D860: _nc_read_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F18FF5: (within /lib/libncurses.so.5.7)
==12156== by 0x6F194BF: _nc_setupterm (in /lib/libncurses.so.5.7)
==12156== by 0x6F19C49: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 83 bytes in 1 blocks are still reachable in loss record 6 of 11
==12156== at 0x4C2260E: malloc (vg_replace_malloc.c:207)
==12156== by 0x6F1A85F: _nc_tparm_analyze (in /lib/libncurses.so.5.7)
==12156== by 0x6F1AAC9: tparm (in /lib/libncurses.so.5.7)
==12156== by 0x6F1E010: _nc_trim_sgr0 (in /lib/libncurses.so.5.7)
==12156== by 0x6F19DC8: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 208 bytes in 1 blocks are still reachable in loss record 7 of 11
==12156== at 0x4C203E4: calloc (vg_replace_malloc.c:397)
==12156== by 0x6F194A5: _nc_setupterm (in /lib/libncurses.so.5.7)
==12156== by 0x6F19C49: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 1,024 bytes in 1 blocks are still reachable in loss record 8 of
11
==12156== at 0x4C22741: realloc (vg_replace_malloc.c:429)
==12156== by 0x52DEE6D: xrealloc (in /lib/libreadline.so.5.2)
==12156== by 0x52CAF17: rl_add_funmap_entry (in /lib/libreadline.so.5.2)
==12156== by 0x52CAF62: rl_initialize_funmap (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7338: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 1,347 bytes in 1 blocks are still reachable in loss record 9 of
11
==12156== at 0x4C2260E: malloc (vg_replace_malloc.c:207)
==12156== by 0x6F1CF41: _nc_read_termtype (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D6D2: _nc_read_file_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D860: _nc_read_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F18FF5: (within /lib/libncurses.so.5.7)
==12156== by 0x6F194BF: _nc_setupterm (in /lib/libncurses.so.5.7)
==12156== by 0x6F19C49: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 3,312 bytes in 1 blocks are still reachable in loss record 10 of
11
==12156== at 0x4C203E4: calloc (vg_replace_malloc.c:397)
==12156== by 0x6F1D100: _nc_read_termtype (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D6D2: _nc_read_file_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F1D860: _nc_read_entry (in /lib/libncurses.so.5.7)
==12156== by 0x6F18FF5: (within /lib/libncurses.so.5.7)
==12156== by 0x6F194BF: _nc_setupterm (in /lib/libncurses.so.5.7)
==12156== by 0x6F19C49: tgetent (in /lib/libncurses.so.5.7)
==12156== by 0x52DBAC1: _rl_init_terminal_io (in
/lib/libreadline.so.5.2)
==12156== by 0x52C7322: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156==
==12156== 92,005 bytes in 154 blocks are still reachable in loss record 11
of 11
==12156== at 0x4C2260E: malloc (vg_replace_malloc.c:207)
==12156== by 0x52DEEC8: xmalloc (in /lib/libreadline.so.5.2)
==12156== by 0x52D2C41: (within /lib/libreadline.so.5.2)
==12156== by 0x52D2E2B: rl_read_init_file (in /lib/libreadline.so.5.2)
==12156== by 0x52C7344: rl_initialize (in /lib/libreadline.so.5.2)
==12156== by 0x52C8206: readline (in /lib/libreadline.so.5.2)
==12156== by 0x476D63: main (TransformStandalone.c:427)
==12156==
==12156== LEAK SUMMARY:
==12156== definitely lost: 0 bytes in 0 blocks.
==12156== possibly lost: 0 bytes in 0 blocks.
==12156== still reachable: 98,152 bytes in 165 blocks.
all strings returned from the readline() function are freed subsequently
and also the name of internal funcion (rl_initialize) suggests this is
some internal state
Best regards,
Ondřej Adamovský
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-readline] Feature request for deinitialization function,
Ondřej Adamovský <=