zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-workers@zsh.org>
Subject: Completion crash owing to bad allocation
Date: Wed, 11 May 2011 15:09:09 +0100	[thread overview]
Message-ID: <20110511150909.6fd6dda0@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <87sjsl2wqg.fsf@ft.bewatermyfriend.org>

On Wed, 11 May 2011 15:27:35 +0200
Frank Terbeck <ft@bewatermyfriend.org> wrote:
> I'm running into a segfault, though. The git repository is located in
> `/tmp/linux-2.6'. I've changed a file (fs/adfs/dir.c) slightly and I'm
> doing this:
> 
>   % git add f<tab>
>   % git add fs/<tab>
>   % git add fs/adfs/<tab>
> 
> And that's where the shell crashes. It's a build of today's HEAD.

This seems to be another variant of the "amatches" problem.

amatches is a global in the completion code that holds one version of
the list of matches during completion.  This is on the heap, and because
it's not scoped it's virtually impossible to keep track of the point at
which it becomes invalid.  For extra ease of maintainance, at some point
in the procedure it is deliberately set to point to a permanently
allocated copy.  When the crash happens we are scanning through
some (possibly subtly disguised) part of amatches and examining some
no longer valid memory.

One way to tackle this would be to add a stack corresponding to the
current heap stack, with each level having a unique (up to 32-bit
integer wrap) ID that tells you if that heap variant is valid.  Then
when memory is allocated for use by a Cmgroup it stores the ID
corresponding to the currently pushed heap at the top of the stack
(with a special ID to be used if it was permanently allocated).  Every
time amatches is examined the code could report an error if a heap ID
stored somewhere along the list doesn't correspond to one somewhere on
the current heap debug stack.  (Unfortunately examining amatches at the
point of a popheap() won't work --- the code is lax about marking
amatches as invalid, it just expects you not to access it in that case,
which is part of the problem.)

I won't be doing the completion code debugging, I'm fed up with days of
my life disappearing into code I never seem to get any closer to
understanding and have quite enough else to manage, but if someone
thinks they might get round to that (understanding is optional for now,
we just need to be able to track what's going on with amatches) I'd be
happy to have a go at writing the tools for heap debugging.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  parent reply	other threads:[~2011-05-11 14:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-06 13:03 Speed improvement patch for __git_files and __git_files_relative Nikolai Weibull
2011-05-11 13:27 ` Frank Terbeck
2011-05-11 13:44   ` Mikael Magnusson
2011-05-11 14:09   ` Peter Stephenson [this message]
2011-05-13 23:26     ` Completion crash owing to bad allocation Peter Stephenson
2011-05-14  2:56       ` Bart Schaefer
2011-05-17 12:55 ` Speed improvement patch for __git_files and __git_files_relative Nikolai Weibull
2011-05-17 13:01   ` Frank Terbeck

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=20110511150909.6fd6dda0@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --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).