Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Jan 2008 20:54:47 +0100 (CET)
From:      peter.schuller@infidyne.com
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/119608: [patch] iostat -x leaks memory
Message-ID:  <20080112195447.CD0F423C42D@hyperion.scode.org>
Resent-Message-ID: <200801122000.m0CK05qv072614@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080112195447.CD0F423C42D>