Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: compctl bug with beta17 on Linux



In <zsh-workers@xxxxxxxxxxxxxxx> archive/latest/1024,
Zoltan Hidvegi <hzoli@xxxxxxxxxx> wrote:

> The problem is that cmdstr is initialised in the middle of get_comp_string
> using dupstring() and there is a pushheap() before this and a pophheap()
> after this.  This means that cmdstr will be freed before returning from
> get_comp_string().

Methinks cmdstr is freed by freeheap() in docomplete(), in this case.

> [...] After that, the fix is trivial.

I beg to differ :-)  Stylistical issues aside (freeing a char* before
ever using it, even if it's guaranteed to be initialised with NULL),
Zoltan's patch will fall over, when for whatever reason there's more than
one command position considered in the do/while-loop in get_comp_string().
Invariably this will lead to memory leaks.  For example, when quotes and
newlines are involved:

% somecommand "
> anystring "
            ^ here's the cursor, and completion is requested

cmdstr will point to "anystring", but the memory occupied previously by
"somecommand" won't never be released.  That "anystring" is the result
might be seen as a bug in its own right, but who says that something like
this will never happen?

Your humble servant,
Thorsten




Messages sorted by: Reverse Date, Date, Thread, Author