While attempting to make use of the readline alternate interface, I found what looks like a memory leak in Readline 6.2-8 (Ubuntu 12.04) when run under valgrind. I don't know if this is because I am using rl_callback_read_char() and friends improperly or if this really is a problem with readline. I hope it is the former, and if so I would appreciate the correct usage of the interface, on which documentation seems to be very scant. I have attached a C program that illustrates my usage of readline's interface, and while it works correctly as far as the interface is concerned, whenever I attempt to use Ctrl-R to do a reverse isearch valgrind notices the following memory leak report after I quit. The memory leak does not appear if I do not attempt to search the history.
$ valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 ./rltest
==26946== Memcheck, a memory error detector
==26946== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==26946== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==26946== Command: ./rltest
==26946==
>> hello there
You said: 'hello there'
>> hello there
You said: 'hello there'
>> ==26946==
==26946== HEAP SUMMARY:
==26946== in use at exit: 109,851 bytes in 187 blocks
==26946== total heap usage: 322 allocs, 135 frees, 123,725 bytes allocated
==26946==
==26946== 23 bytes in 1 blocks are definitely lost in loss record 8 of 43
==26946== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26946== by 0x4E5E618: xmalloc (xmalloc.c:61)
==26946== by 0x4E52A7B: expand_prompt (display.c:275)
==26946== by 0x4E53A7D: rl_message (display.c:2185)
==26946== by 0x4E516D1: rl_display_search.isra.0 (isearch.c:198)
==26946== by 0x4E52486: rl_search_history.isra.2 (isearch.c:656)
==26946== by 0x4E44AED: _rl_dispatch_subseq (readline.c:774)
==26946== by 0x4E450F1: readline_internal_char (readline.c:552)
==26946== by 0x4E5A8EC: rl_callback_read_char (callback.c:201)
==26946== by 0x400D0B: main (in /home/dido/rltest)
==26946==
==26946== 24 bytes in 1 blocks are definitely lost in loss record 11 of 43
==26946== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26946== by 0x4E5E618: xmalloc (xmalloc.c:61)
==26946== by 0x4E52A7B: expand_prompt (display.c:275)
==26946== by 0x4E53A7D: rl_message (display.c:2185)
==26946== by 0x4E516D1: rl_display_search.isra.0 (isearch.c:198)
==26946== by 0x4E520E6: _rl_isearch_dispatch (isearch.c:621)
==26946== by 0x4E52553: _rl_isearch_callback (isearch.c:693)
==26946== by 0x4E5A7FF: rl_callback_read_char (callback.c:134)
==26946== by 0x400D0B: main (in /home/dido/rltest)
==26946==
==26946== LEAK SUMMARY:
==26946== definitely lost: 47 bytes in 2 blocks
==26946== indirectly lost: 0 bytes in 0 blocks
==26946== possibly lost: 0 bytes in 0 blocks
==26946== still reachable: 109,804 bytes in 185 blocks
==26946== suppressed: 0 bytes in 0 blocks
==26946== Reachable blocks (those to which a pointer was found) are not shown.
==26946== To see them, rerun with: --leak-check=full --show-reachable=yes
==26946==
==26946== For counts of detected and suppressed errors, rerun with: -v
==26946== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2 from 2)