From owner-svn-src-head@FreeBSD.ORG Wed May 21 17:34:51 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6B650A33; Wed, 21 May 2014 17:34:51 +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 58A172CFB; Wed, 21 May 2014 17:34:51 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4LHYpso020749; Wed, 21 May 2014 17:34:51 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4LHYpoi020747; Wed, 21 May 2014 17:34:51 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201405211734.s4LHYpoi020747@svn.freebsd.org> From: Marcel Moolenaar Date: Wed, 21 May 2014 17:34:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r266509 - head/usr.bin/mkimg 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: Wed, 21 May 2014 17:34:51 -0000 Author: marcel Date: Wed May 21 17:34:50 2014 New Revision: 266509 URL: http://svnweb.freebsd.org/changeset/base/266509 Log: Fix CID 1215129: move the call to lseek(2) before the call to malloc(3) so that the error path (taken due to lseek(2) failing) isn't leaking memory. Modified: head/usr.bin/mkimg/image.c Modified: head/usr.bin/mkimg/image.c ============================================================================== --- head/usr.bin/mkimg/image.c Wed May 21 17:22:41 2014 (r266508) +++ head/usr.bin/mkimg/image.c Wed May 21 17:34:50 2014 (r266509) @@ -98,11 +98,11 @@ image_copyout(int fd) ofs = lseek(fd, 0L, SEEK_CUR); + if (lseek(image_fd, 0, SEEK_SET) != 0) + return (errno); buffer = malloc(BUFFER_SIZE); if (buffer == NULL) return (errno); - if (lseek(image_fd, 0, SEEK_SET) != 0) - return (errno); error = 0; while (1) { rdsz = read(image_fd, buffer, BUFFER_SIZE);