From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Deadlock when receiving kill-signal from child process
Date: Mon, 10 Aug 2015 12:34:45 -0700 [thread overview]
Message-ID: <150810123445.ZM1612@torch.brasslantern.com> (raw)
In-Reply-To: <CA+=GgY4+utmAzyYyBn1wQy1BhFcrzk+DiN+FcqYOpUdrSHhbGg@mail.gmail.com>
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
next prev parent reply other threads:[~2015-08-10 19:34 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-03 11:25 Mathias Fredriksson
2015-08-03 15:52 ` Bart Schaefer
2015-08-03 20:36 ` Mathias Fredriksson
2015-08-03 20:58 ` Bart Schaefer
2015-08-04 21:52 ` Mathias Fredriksson
2015-08-05 0:05 ` Mathias Fredriksson
2015-08-05 6:53 ` Bart Schaefer
2015-08-05 10:37 ` Mathias Fredriksson
2015-08-05 15:52 ` Bart Schaefer
2015-08-05 16:05 ` Mathias Fredriksson
2015-08-05 18:52 ` Bart Schaefer
2015-08-05 19:11 ` Mathias Fredriksson
2015-08-05 20:20 ` Bart Schaefer
2015-08-05 21:49 ` Mathias Fredriksson
2015-08-06 5:06 ` Bart Schaefer
2015-08-06 8:24 ` Mathias Fredriksson
2015-08-06 15:54 ` Bart Schaefer
2015-08-07 0:45 ` Mathias Fredriksson
2015-08-07 5:39 ` Bart Schaefer
2015-08-09 13:53 ` Mathias Fredriksson
2015-08-09 23:42 ` Bart Schaefer
2015-08-10 0:02 ` Mikael Magnusson
2015-08-10 0:16 ` Mathias Fredriksson
2015-08-10 1:47 ` Bart Schaefer
2015-08-10 2:02 ` Mikael Magnusson
2015-08-10 15:59 ` Bart Schaefer
2015-08-10 17:30 ` Mathias Fredriksson
2015-08-10 0:36 ` Bart Schaefer
2015-08-10 0:29 ` Bart Schaefer
2015-08-10 19:34 ` Bart Schaefer [this message]
2015-08-10 21:17 ` Mathias Fredriksson
2015-08-10 22:53 ` Mathias Fredriksson
2015-08-11 0:53 ` Bart Schaefer
2015-08-11 12:17 ` Mathias Fredriksson
2015-08-11 14:38 ` Mathias Fredriksson
2015-08-11 15:07 ` Bart Schaefer
2015-08-11 15:22 ` Mathias Fredriksson
2015-08-11 4:06 ` Running commands in a zpty worker Bart Schaefer
2015-08-11 13:14 ` Mathias Fredriksson
2015-08-11 14:35 ` Mathias Fredriksson
2015-08-11 14:37 ` Bart Schaefer
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=150810123445.ZM1612@torch.brasslantern.com \
--to=schaefer@brasslantern.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).