Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: crash/hang with gcc 5+ -O2 and --enable-zsh-mem
- X-seq: zsh-workers 42401
- From: Joey Pabalinas <joeypabalinas@xxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: crash/hang with gcc 5+ -O2 and --enable-zsh-mem
- Date: Sat, 24 Feb 2018 21:06:37 -1000
- Cc: zsh workers <zsh-workers@xxxxxxx>, Joey Pabalinas <joeypabalinas@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Hd2QI08ynQOfDw9yabj/4vg9+d7rXf/2M7xKeOiwvyQ=; b=mjbYOP8fSOTRuWkp6d8oAfWzz1D0KndPEi+SNfAGPlryf10W7mRda8p97bHwRO2+Za Nj/Xm94CoaAE5EY+ascor9AkX43KRunUuBsuYvVvoPA9VcbMOpytAnB64TdGQAOsmo5a rvUSCh8BXhhsUT7UNpkb7tXOfCaUChARtPGJmmy8XbRWb+yz3NpXDXyQSq6RzSGDloKT lR5QtfOftX0NiYHIZWYFOW7Uw1+0FoWSFjAVNd8zvSnVGdPPrEI+g/wcf/zclvPXi9lz HU2m1G+iCf7jcNfVIxskq8V4jQF4kvbvAawKEhRhoIP4IhhTZnKt0jrKTrMF9f/k7Xgg mDXw==
- In-reply-to: <20180225001334.fzsdcy67cnosvj5z@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHYJk3ScwwWYGBHVXDASaWDkxamUFYQjAgEzEWD=NhcbOTVsrA@mail.gmail.com> <20180225001334.fzsdcy67cnosvj5z@gmail.com>
On Sat, Feb 24, 2018 at 02:13:34PM -1000, Joey Pabalinas wrote:
> The only fix I could find which didn't requiring substantial
> reimplementation of the memory management functions was to replace
> the malloc() call in calloc() with realloc() instead. With a NULL `p`
> argument realloc() behaves exactly the same as malloc() does, and
> (at least on my system) gcc doesn't seem to consider realloc() a
> candidate for sibling call optimizations; give this patch a try
> and _hopefully_ this is a viable solution.
On second thought, doing it this way is probably a *little* bit better; the
needless initialization of `r` to NULL is avoided, and it also makes the
purpose of using realloc() over malloc() a *tiny* bit more explicit:
Signed-off-by: Joey Pabalinas <joeypabalinas@xxxxxxxxx>
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/Src/mem.c b/Src/mem.c
index 840bbb6e4a4eb6fd73..f1208197b3ddac2139 100644
--- a/Src/mem.c
+++ b/Src/mem.c
@@ -1719,7 +1719,13 @@ calloc(MALLOC_ARG_T n, MALLOC_ARG_T size)
if (!(l = n * size))
return (MALLOC_RET_T) m_high;
- r = malloc(l);
+ /*
+ * use realloc() (with a NULL `p` argument it behaves exactly the same
+ * as malloc() does) to prevent an infinite loop caused by sibling-call
+ * optimizations (the malloc() call would otherwise be replaced by an
+ * unconditional branch back to line 1719 ad infinitum).
+ */
+ r = realloc(NULL, l);
memset(r, 0, l);
--
2.16.2
Attachment:
signature.asc
Description: PGP signature
Messages sorted by:
Reverse Date,
Date,
Thread,
Author