svn commit: r197062 - head/sys/dev/syscons/daemon
John Baldwin
jhb at FreeBSD.org
Thu Sep 10 12:58:38 UTC 2009
Author: jhb
Date: Thu Sep 10 12:58:37 2009
New Revision: 197062
URL: http://svn.freebsd.org/changeset/base/197062
Log:
Don't malloc a buffer while holding the prison0 mutex. Instead, use a loop
where we figure out the hostname length under the lock, malloc the buffer
with the lock dropped, then recheck the length under the lock and loop again
if the buffer is now too small.
Tested by: Norbert Koch nkoch demig de
MFC after: 3 days
Modified:
head/sys/dev/syscons/daemon/daemon_saver.c
Modified: head/sys/dev/syscons/daemon/daemon_saver.c
==============================================================================
--- head/sys/dev/syscons/daemon/daemon_saver.c Thu Sep 10 12:55:09 2009 (r197061)
+++ head/sys/dev/syscons/daemon/daemon_saver.c Thu Sep 10 12:58:37 2009 (r197062)
@@ -351,11 +351,23 @@ daemon_saver(video_adapter_t *adp, int b
static int
daemon_init(video_adapter_t *adp)
{
+ size_t hostlen;
mtx_lock(&prison0.pr_mtx);
- messagelen = strlen(prison0.pr_hostname) + 3 + strlen(ostype) + 1 +
- strlen(osrelease);
- message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
+ for (;;) {
+ hostlen = strlen(prison0.pr_hostname);
+ mtx_unlock(&prison0.pr_mtx);
+
+ messagelen = hostlen + 3 + strlen(ostype) + 1 +
+ strlen(osrelease);
+ message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
+ mtx_lock(&prison0.pr_mtx);
+ if (hostlen < strlen(prison0.pr_hostname)) {
+ free(message, M_DEVBUF);
+ continue;
+ }
+ break;
+ }
sprintf(message, "%s - %s %s", prison0.pr_hostname, ostype, osrelease);
mtx_unlock(&prison0.pr_mtx);
blanked = 0;
More information about the svn-src-all
mailing list