From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1841 invoked by alias); 10 Aug 2015 19:34:53 -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: 36084 Received: (qmail 1626 invoked from network); 10 Aug 2015 19:34:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=yr7cJb5EDkIkjcNN5H9O4gs4FevlyubkI1xFCPM+Oso=; b=XX5nIaXhtHsbAdlc+Zr0I/95+uEnh7+p9MXTnOU/xi00uQhl4Wd77vVB9FBp6eC8pw P27XBqRb+XqqtuLJlQMp0b3FI4TrbcD5zCmlDoIz60pu40QidD5oz2Tv47gM5O7c9W07 8LRFf5fg0+25wuPRjuBcXJ9R8yC6wmKPslGeNfBulNB3kPQxQ4qG2weZL0rowqgZbg8s 6nd9ntrdiOYudvu+HDyVIfPAU7hFXav93ThnUtvAPbKCpidImGWZs/jKXsTJZtj9AWa7 P0Jq2FxqZ9kudQ3/21P4/kanu6INuJ0X2wSE5PY6ztEw/bFKJHzfV47NwKGR79WhMx7J Cxcw== X-Gm-Message-State: ALoCoQkpnDMfpYMGhSJsZJk4DyWa3vdOgLza8yh5Ve3A0XJVPd3rbZlFAyntF2MN82WQ6lCIlQWV X-Received: by 10.202.185.133 with SMTP id j127mr20334555oif.9.1439235289481; Mon, 10 Aug 2015 12:34:49 -0700 (PDT) From: Bart Schaefer Message-Id: <150810123445.ZM1612@torch.brasslantern.com> Date: Mon, 10 Aug 2015 12:34:45 -0700 In-Reply-To: Comments: In reply to Mathias Fredriksson "Re: Deadlock when receiving kill-signal from child process" (Aug 9, 4:53pm) References: <150803085228.ZM24837@torch.brasslantern.com> <150803135818.ZM24977@torch.brasslantern.com> <150804235400.ZM9958@torch.brasslantern.com> <150805085258.ZM17673@torch.brasslantern.com> <150805115249.ZM7158@torch.brasslantern.com> <150805132014.ZM7746@torch.brasslantern.com> <150805220656.ZM18545@torch.brasslantern.com> <150806085451.ZM402@torch.brasslantern.com> <150806223906.ZM17762@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Deadlock when receiving kill-signal from child process MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 9, 4:53pm, Mathias Fredriksson wrote: } } At first I thought there were absolutely no more deadlocks, but I } managed to repeatedly produce one (when _not_ disowning the child } processes). Reviewing the code again has led me to realize / recall that although we consistently use our signal-safe wrappers around malloc(), the similar wrapper around free() is enabled only when the configuration has included --enable-zsh-mem. Further, we're inconsistent about using the signal-safe wrapper for realloc() [a better one gets compiled in with --enable-zsh-mem]. The last few stack traces you've sent [except for the most recent one mentioning fork()] indicate clashes between realloc() and free(), even though other parts of the stack look wonky. Even with --enable-zsh-mem the realloc() wrapper sometimes calls malloc() unsafely, though that wouldn't be hard to fix. A quick grep indicates 34 realloc() and 224 free() scattered around the code. Probably many of them are already within queue_signals(). The patch below fixes four of them that your stack traces seem to point to as particular culprits. It's probably not worth it to try to pre-emptively change all the others. If you are still able to create deadlocks after the below, I'd also ask you to try configuring with --enable-zsh-mem and see if that gets rid of any remaining deadlocks. It'd also be interesting to benchmark a few versions of zsh including the latest from git, on things like how long **/* takes in a big tree, how long "make check" takes to run, etc., both with and without using --enable-zsh-mem. Any volunteers? diff --git a/Src/glob.c b/Src/glob.c index f82c3bd..3af4690 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -257,7 +257,7 @@ addpath(char *s, int l) { DPUTS(!pathbuf, "BUG: pathbuf not initialised"); while (pathpos + l + 1 >= pathbufsz) - pathbuf = realloc(pathbuf, pathbufsz *= 2); + pathbuf = zrealloc(pathbuf, pathbufsz *= 2); while (l--) pathbuf[pathpos++] = *s++; pathbuf[pathpos++] = '/'; diff --git a/Src/text.c b/Src/text.c index cf73004..3978a26 100644 --- a/Src/text.c +++ b/Src/text.c @@ -77,7 +77,7 @@ taddpending(char *str1, char *str2) */ if (tpending) { int oldlen = strlen(tpending); - tpending = realloc(tpending, len + oldlen); + tpending = zrealloc(tpending, len + oldlen); sprintf(tpending + oldlen, "%s%s", str1, str2); } else { tpending = (char *)zalloc(len); @@ -110,7 +110,7 @@ taddchr(int c) tptr--; return; } - tbuf = realloc(tbuf, tsiz *= 2); + tbuf = zrealloc(tbuf, tsiz *= 2); tlim = tbuf + tsiz; tptr = tbuf + tsiz / 2; } @@ -130,7 +130,7 @@ taddstr(char *s) if (!tbuf) return; - tbuf = realloc(tbuf, tsiz *= 2); + tbuf = zrealloc(tbuf, tsiz *= 2); tlim = tbuf + tsiz; tptr = tbuf + x; } -- Barton E. Schaefer