Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Aug 1999 00:20:48 -0400 (EDT)
From:      steve@copacetic.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   misc/13368: Memory leak in -current pthreads select() implementation
Message-ID:  <199908250420.AAA32479@cfg2.navinet.net>

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

>Number:         13368
>Category:       misc
>Synopsis:       Memory leak in -current pthreads select() implementation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 24 21:20:01 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Steve Bernacki, Jr.
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
NaviNet, Inc.
>Environment:

	FreeBSD testbed.eng.navinet.net 3.2-RELEASE FreeBSD 3.2-RELEASE #0: Tue May 18 04:05:08
 GMT 1999     jkh@cathair:/usr/src/sys/compile/GENERIC  i386

>Description:

	FreeBSD's pthreads implements select() internally as poll().  In doing this,
	it dynamically allocates memory (one per thread) to store the pollfd struct.
	While subsequent calls to poll() in the same thread will reuse this memory,
	it is never free()ed when the thread is exited.
	

>How-To-Repeat:

	This problem can be seen in threaded applications that frequently spawn
	threads (one per transaction, for example) that call select().  Memory usage
	for this process will steadily increase over time.

>Fix:
	
	Applying the following patch to uthread_exit.c fixed the steady increase in
	memory:


*** uthread_exit.c.orig	Thu Aug  5 19:16:47 1999
--- uthread_exit.c	Tue Aug 24 23:42:51 1999
***************
*** 134,139 ****
--- 134,145 ----
  		_thread_cleanupspecific();
  	}
  
+ 	/* Free thread-specific poll_data structure, if allocated */
+ 	if (_thread_run->poll_data.fds != NULL) {
+ 		free(_thread_run->poll_data.fds);
+ 		_thread_run->poll_data.fds = NULL;
+ 	}
+ 
  	/*
  	 * Defer signals to protect the scheduling queues from access
  	 * by the signal handler:


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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