From owner-svn-src-all@FreeBSD.ORG Tue Apr 20 14:22:29 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 964751065670; Tue, 20 Apr 2010 14:22:29 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8319B8FC14; Tue, 20 Apr 2010 14:22:29 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o3KEMTgp050819; Tue, 20 Apr 2010 14:22:29 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o3KEMTao050817; Tue, 20 Apr 2010 14:22:29 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201004201422.o3KEMTao050817@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 20 Apr 2010 14:22:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r206898 - head/lib/libc/stdlib X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2010 14:22:29 -0000 Author: kib Date: Tue Apr 20 14:22:29 2010 New Revision: 206898 URL: http://svn.freebsd.org/changeset/base/206898 Log: Free() is not allowed to modify errno, remove safety brackets around it [1]. Add small optimization, do not copy a string to the buffer that is to be freed immediately after. Noted by: jh [1] Reviewed by: jh MFC after: 2 weeks Modified: head/lib/libc/stdlib/realpath.c Modified: head/lib/libc/stdlib/realpath.c ============================================================================== --- head/lib/libc/stdlib/realpath.c Tue Apr 20 12:22:06 2010 (r206897) +++ head/lib/libc/stdlib/realpath.c Tue Apr 20 14:22:29 2010 (r206898) @@ -84,12 +84,10 @@ realpath(const char * __restrict path, c left_len = strlcpy(left, path + 1, sizeof(left)); } else { if (getcwd(resolved, PATH_MAX) == NULL) { - strlcpy(resolved, ".", PATH_MAX); - if (m) { - serrno = errno; + if (m) free(resolved); - errno = serrno; - } + else + strlcpy(resolved, ".", PATH_MAX); return (NULL); } resolved_len = strlen(resolved); @@ -168,11 +166,8 @@ realpath(const char * __restrict path, c errno = serrno; return (resolved); } - if (m) { - serrno = errno; + if (m) free(resolved); - errno = serrno; - } return (NULL); } if (S_ISLNK(sb.st_mode)) { @@ -184,11 +179,8 @@ realpath(const char * __restrict path, c } slen = readlink(resolved, symlink, sizeof(symlink) - 1); if (slen < 0) { - if (m) { - serrno = errno; + if (m) free(resolved); - errno = serrno; - } return (NULL); } symlink[slen] = '\0';