zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] allocate origline by ztrdup(), not by dupstring()
Date: Tue, 16 Jun 2015 18:54:25 +0200	[thread overview]
Message-ID: <24973.1434473665@thecus.kiddle.eu> (raw)
In-Reply-To: <1000D010-B07A-4F19-A566-8CA95B061D58@kba.biglobe.ne.jp>

On 7 Jan, "Jun T." wrote:
> Currently, domenuselect() allocates origline in heap by dupstring(),
> but if menuselect() is called directly as a widget then the heap has
> already been freed (and may have been re-used for other variables).

I noticed problems which I traced back to this change.

> diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
> @@ -2882,7 +2882,8 @@ domenuselect(Hookdef dummy, Chdata dat)
> -	    origline = u->origline;
> +	    zsfree(origline);
> +	    origline = ztrdup(u->origline);

This part is run when pressing backspace, it seems to always be the case
that origline == u->origline before this block runs. So it is copying freed
memory. I tried the obvious change of checking that condition first but
that seems to result in deleted characters being treated as if they were
part of the original string before completion. It is also calling zsfree
on origline before ther very first time that it is initialised.

I think it might be easier to approach this by revisiting the original
problem. I've tried binding a widget direct to menuselect but haven't
been able to get anything odd to happen.

origline is initialised in docomplete. pushheap() is done later in
do_completion(). That would seem not to be a problem for a later
menu-select widget accessing origline. I am, however, suspicious of the
line which does origline = modeline because the value of modeline does,
I think, come from dupstring() while completion is active. Setting a
breakpoint at that line, I've only managed to trigger it when origline
and modeline are already equal (in strcmp terms) so I'm not sure of the
situation that code is there to handle. Any ideas?

Oliver


  parent reply	other threads:[~2015-06-16 17:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-06 16:37 Jun T.
2015-01-06 18:23 ` Jun T.
2015-06-16 16:54 ` Oliver Kiddle [this message]
2015-06-17 16:24   ` Jun T.
2015-06-21 11:53   ` Jun T.
2015-06-22  8:36     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24973.1434473665@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).