bin/119608: [patch] iostat -x leaks memory

peter.schuller at infidyne.com peter.schuller at infidyne.com
Sat Jan 12 12:00:05 PST 2008


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


More information about the freebsd-bugs mailing list