From owner-svn-src-head@FreeBSD.ORG Thu Jul 10 21:46:57 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A71F996A; Thu, 10 Jul 2014 21:46:57 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 94FB02814; Thu, 10 Jul 2014 21:46:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6ALkvxW032882; Thu, 10 Jul 2014 21:46:57 GMT (envelope-from mjg@svn.freebsd.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6ALkvLC032881; Thu, 10 Jul 2014 21:46:57 GMT (envelope-from mjg@svn.freebsd.org) Message-Id: <201407102146.s6ALkvLC032881@svn.freebsd.org> From: Mateusz Guzik Date: Thu, 10 Jul 2014 21:46:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r268509 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2014 21:46:57 -0000 Author: mjg Date: Thu Jul 10 21:46:57 2014 New Revision: 268509 URL: http://svnweb.freebsd.org/changeset/base/268509 Log: Don't make a temporary copy of fixed sysctl strings. Modified: head/sys/kern/kern_sysctl.c Modified: head/sys/kern/kern_sysctl.c ============================================================================== --- head/sys/kern/kern_sysctl.c Thu Jul 10 21:11:48 2014 (r268508) +++ head/sys/kern/kern_sysctl.c Thu Jul 10 21:46:57 2014 (r268509) @@ -1216,26 +1216,33 @@ int sysctl_handle_string(SYSCTL_HANDLER_ARGS) { size_t outlen; - int error = 0; + int error = 0, ro_string = 0; /* * A zero-length buffer indicates a fixed size read-only * string: */ - if (arg2 == 0) + if (arg2 == 0) { arg2 = strlen((char *)arg1) + 1; + ro_string = 1; + } if (req->oldptr != NULL) { char *tmparg; - /* try to make a coherent snapshot of the string */ - tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK); - memcpy(tmparg, arg1, arg2); + if (ro_string) { + tmparg = arg1; + } else { + /* try to make a coherent snapshot of the string */ + tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK); + memcpy(tmparg, arg1, arg2); + } outlen = strnlen(tmparg, arg2 - 1) + 1; error = SYSCTL_OUT(req, tmparg, outlen); - free(tmparg, M_SYSCTLTMP); + if (!ro_string) + free(tmparg, M_SYSCTLTMP); } else { outlen = strnlen((char *)arg1, arg2 - 1) + 1; error = SYSCTL_OUT(req, NULL, outlen);