Message100492
Note the following comment elsewhere in Modules/readline.c:
/* the history docs don't say so, but the address of state
changes each time history_get_history_state is called
which makes me think it's freshly malloc'd memory...
on the other hand, the address of the last line stays the
same as long as history isn't extended, so it appears to
be malloc'd but managed by the history package... */
free(state);
It is indeed not documented that state is malloced, but the implementation of history_get_history_state () is as follows:
/* Return the current HISTORY_STATE of the history. */
HISTORY_STATE *
history_get_history_state ()
{
HISTORY_STATE *state;
state = (HISTORY_STATE *)xmalloc (sizeof (HISTORY_STATE));
state->entries = the_history;
state->offset = history_offset;
state->length = history_length;
state->size = history_size;
state->flags = 0;
if (history_stifled)
state->flags |= HS_STIFLED;
return (state);
}
xmalloc () is an error checking wrapper around malloc, so free () can be used to deallocate the memory.
On the other hand it seems wasteful to request full state in a function that only needs history_length which is directly exported by the readline library. I am attaching a patch that reads history_length directly. |
|
Date |
User |
Action |
Args |
2010-03-05 17:06:40 | Alexander.Belopolsky | set | recipients:
+ Alexander.Belopolsky, stefanholek |
2010-03-05 17:06:40 | Alexander.Belopolsky | set | messageid: <1267808800.04.0.987736248845.issue8065@psf.upfronthosting.co.za> |
2010-03-05 17:06:38 | Alexander.Belopolsky | link | issue8065 messages |
2010-03-05 17:06:37 | Alexander.Belopolsky | create | |
|