From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16364 invoked by alias); 6 Apr 2014 07:06:08 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32531 Received: (qmail 27158 invoked from network); 6 Apr 2014 07:05:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140406000541.ZM14625@torch.brasslantern.com> Date: Sun, 06 Apr 2014 00:05:41 -0700 In-reply-to: =?iso-8859-1?Q?=3C53381887=2E2040201=40physik=2Etu-berlin=2Ed?= =?iso-8859-1?Q?e=3E?= =?iso-8859-1?Q?Comments=3A_In_reply_to_Sebastian_G=F6tte_=3Cjaseg=40physi?= =?iso-8859-1?Q?k=2Etu-berlin=2Ede=3E?= =?iso-8859-1?Q?________=22Segfault_in_hrealloc_somewhere_between_rpromts_?= =?iso-8859-1?Q?and_syntax_highlighting=22_=28Mar_30=2C__3=3A13pm=29?= References: <53381887.2040201@physik.tu-berlin.de> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: =?iso-8859-1?Q?Sebastian_G=F6tte?= , zsh-workers@zsh.org Subject: Re: Segfault in hrealloc somewhere between rpromts and syntax highlighting MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: quoted-printable I'm only a little surprised that nobody else responded to this while I was offline. It's been known for quite some time that there are crash bugs in region_highlight that are violently tickled by zsh-syntax-highlighting. None of the regular developers uses zsh-syntax-highlighting as far as I know (I certainly don't), so we're not encountering this directly. Unfortunately, the actual error is somewhere far removed from the point where the crash occurs -- something is leaving a corrupted heap as an unintentional booby-trap for hrealloc to trip only after the evidence has been destroyed -- so the stack traces we get are not helpful. I do have one question for you: On Mar 30, 3:13pm, Sebastian G=F6tte said this was a minimal zshrc: }=20 } setopt promptsubst } RPROMPT=3D'$("%s")' } ZSH_HIGHLIGHT_HIGHLIGHTERS=3D(main brackets pattern) } source ~/dotfiles/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh If I make that my .zshrc (with appropriate tweak to the path to the zsh-syntax-highlighting clone), I get this: zsh: command not found: %s=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 torch%=20 zsh: command not found: %s=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 torch%=20 Obviously something is missing here. What's supposed to fill in that %s in the RPROMPT? I'm otherwise not able to reproduce the crash with the sample you provided, though running under valgrind creates a continuous stream of leaked memory warnings during highlighting. Here's a patch for those leaks. diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index 8ce6787..80be27f 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -444,6 +444,7 @@ void set_region_highlight(UNUSED(Param pm), char **aval) { int len; + char **av =3D aval; struct region_highlight *rhp; =20 len =3D aval ? arrlen(aval) : 0; @@ -490,6 +491,8 @@ set_region_highlight(UNUSED(Param pm), char **aval) =20 match_highlight(strp, &rhp->atr); } + + freearray(av); } =20 =20 diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 3c7cff9..b916bd6 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -2795,6 +2795,7 @@ doexpandhist(void) if (!err) { zlemetacs =3D excs; if (strcmp(zlemetaline, ol)) { + zle_restore_positions(); unmetafy_line(); /* For vi mode -- reset the beginning-of-insertion pointer * * to the beginning of the line. This seems a little silly, * diff --git a/Src/hist.c b/Src/hist.c index 1845bd8..1624912 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -1764,7 +1764,8 @@ chrealpath(char **junkptr) str++; } =20 - *junkptr =3D metafy(bicat(real, nonreal), -1, META_HEAPDUP); + *junkptr =3D metafy(str =3D bicat(real, nonreal), -1, META_HEAPDUP); + zsfree(str); #ifdef HAVE_CANONICALIZE_FILE_NAME free(real); #endif