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

Re: Segfault in hrealloc somewhere between rpromts and syntax highlighting



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ötte said this was a minimal zshrc:
} 
} setopt promptsubst
} RPROMPT='$("%s")'
} ZSH_HIGHLIGHT_HIGHLIGHTERS=(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                                                      
torch% 
zsh: command not found: %s                                                      
torch% 

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 = aval;
     struct region_highlight *rhp;
 
     len = aval ? arrlen(aval) : 0;
@@ -490,6 +491,8 @@ set_region_highlight(UNUSED(Param pm), char **aval)
 
 	match_highlight(strp, &rhp->atr);
     }
+
+    freearray(av);
 }
 
 
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 = 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++;
     }
 
-    *junkptr = metafy(bicat(real, nonreal), -1, META_HEAPDUP);
+    *junkptr = metafy(str = bicat(real, nonreal), -1, META_HEAPDUP);
+    zsfree(str);
 #ifdef HAVE_CANONICALIZE_FILE_NAME
     free(real);
 #endif



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