From owner-freebsd-bugs@FreeBSD.ORG Sat Jan 12 20:00:05 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D6AE016A41A for ; Sat, 12 Jan 2008 20:00:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A161013C46B for ; Sat, 12 Jan 2008 20:00:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0CK05bA072615 for ; Sat, 12 Jan 2008 20:00:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0CK05qv072614; Sat, 12 Jan 2008 20:00:05 GMT (envelope-from gnats) Resent-Date: Sat, 12 Jan 2008 20:00:05 GMT Resent-Message-Id: <200801122000.m0CK05qv072614@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, peter.schuller@infidyne.com Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A15C616A419 for ; Sat, 12 Jan 2008 19:54:49 +0000 (UTC) (envelope-from scode@hyperion.scode.org) Received: from hyperion.scode.org (hyperion.scode.org [85.17.42.115]) by mx1.freebsd.org (Postfix) with ESMTP id 5568513C442 for ; Sat, 12 Jan 2008 19:54:48 +0000 (UTC) (envelope-from scode@hyperion.scode.org) Received: by hyperion.scode.org (Postfix, from userid 1001) id CD0F423C42D; Sat, 12 Jan 2008 20:54:47 +0100 (CET) Message-Id: <20080112195447.CD0F423C42D@hyperion.scode.org> Date: Sat, 12 Jan 2008 20:54:47 +0100 (CET) From: peter.schuller@infidyne.com To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/119608: [patch] iostat -x leaks memory X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: peter.schuller@infidyne.com List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jan 2008 20:00:05 -0000 >Number: 119608 >Category: bin >Synopsis: [patch] iostat -x leaks memory >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Jan 12 20:00:05 UTC 2008 >Closed-Date: >Last-Modified: >Originator: peter.schuller@infidyne.com >Release: FreeBSD 7.0 BETA 3 >Organization: >Environment: FreeBSD prometheus.scode.org 7.0-BETA3 FreeBSD 7.0-BETA3 #0: Wed Nov 28 23:06:52 CET 2007 scode@prometheus.scode.org:/usr/obj/usr/src/sys/GENERIC amd64 (patch against slightly newer RELENG_7 for source code management reasons) >Description: When using -x, iostat leaks memory indefinitely due to the use of asprintf() without freeing the allocated buffer. Also, the return value of asprintf() is not checked and undefined behavior will ensue if it fails to allocate memory. >How-To-Repeat: >Fix: --- iostat.c.orig 2008-01-12 20:49:31.564883495 +0100 +++ iostat.c 2008-01-12 20:53:24.195670928 +0100 @@ -735,9 +735,10 @@ } if (xflag > 0) { - asprintf(&devname, "%s%d", - cur.dinfo->devices[di].device_name, - cur.dinfo->devices[di].unit_number); + if (asprintf(&devname, "%s%d", + cur.dinfo->devices[di].device_name, + cur.dinfo->devices[di].unit_number) == -1) + errx(1, "asprintf() failed (out of memory?)"); /* * If zflag is set, skip any devices with zero I/O. */ @@ -781,6 +782,7 @@ } printf("\n"); } + free(devname); } else if (oflag > 0) { int msdig = (ms_per_transaction < 100.0) ? 1 : 0; >Release-Note: >Audit-Trail: >Unformatted: