Date: Mon, 14 Sep 2009 16:13:12 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r197194 - in stable/8/sys: . amd64/include/xen cddl/contrib/opensolaris contrib/dev/acpica contrib/pf dev/coretemp dev/syscons/daemon dev/xen/xenpci Message-ID: <200909141613.n8EGDCEs059584@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Mon Sep 14 16:13:12 2009 New Revision: 197194 URL: http://svn.freebsd.org/changeset/base/197194 Log: MFC 197062: 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. Approved by: re (kib) Modified: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/coretemp/coretemp.c (props changed) stable/8/sys/dev/syscons/daemon/daemon_saver.c stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/syscons/daemon/daemon_saver.c ============================================================================== --- stable/8/sys/dev/syscons/daemon/daemon_saver.c Mon Sep 14 15:53:30 2009 (r197193) +++ stable/8/sys/dev/syscons/daemon/daemon_saver.c Mon Sep 14 16:13:12 2009 (r197194) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909141613.n8EGDCEs059584>