Date: Sat, 11 Nov 2017 21:50:36 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325725 - head/sys/kern Message-ID: <201711112150.vABLoaOl033503@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Sat Nov 11 21:50:36 2017 New Revision: 325725 URL: https://svnweb.freebsd.org/changeset/base/325725 Log: sysctl: try to avoid malloc in name2oid name2oid is called all the time and passed names are almost always very short (< 16 characters). Modified: head/sys/kern/kern_sysctl.c Modified: head/sys/kern/kern_sysctl.c ============================================================================== --- head/sys/kern/kern_sysctl.c Sat Nov 11 20:12:48 2017 (r325724) +++ head/sys/kern/kern_sysctl.c Sat Nov 11 21:50:36 2017 (r325725) @@ -1209,17 +1209,21 @@ sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS) int error, oid[CTL_MAXNAME], len = 0; struct sysctl_oid *op = NULL; struct rm_priotracker tracker; + char buf[32]; if (!req->newlen) return (ENOENT); if (req->newlen >= MAXPATHLEN) /* XXX arbitrary, undocumented */ return (ENAMETOOLONG); - p = malloc(req->newlen+1, M_SYSCTL, M_WAITOK); + p = buf; + if (req->newlen >= sizeof(buf)) + p = malloc(req->newlen+1, M_SYSCTL, M_WAITOK); error = SYSCTL_IN(req, p, req->newlen); if (error) { - free(p, M_SYSCTL); + if (p != buf) + free(p, M_SYSCTL); return (error); } @@ -1229,7 +1233,8 @@ sysctl_sysctl_name2oid(SYSCTL_HANDLER_ARGS) error = name2oid(p, oid, &len, &op); SYSCTL_RUNLOCK(&tracker); - free(p, M_SYSCTL); + if (p != buf) + free(p, M_SYSCTL); if (error) return (error);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711112150.vABLoaOl033503>