[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#162584: marked as done (memory leak in gethostbyname_r)



Your message dated Sat, 17 Jul 2004 18:27:28 +0900
with message-id <81zn5zasqn.wl@omega.webmasters.gr.jp>
and subject line Bug#162584: memory leak in gethostbyname_r
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 27 Sep 2002 12:33:53 +0000
>From joern@heissler.de Fri Sep 27 07:33:52 2002
Return-path: <joern@heissler.de>
Received: from p5089a875.dip.t-dialin.net (server.localnet) [80.137.168.117] (mail)
	by master.debian.org with esmtp (Exim 3.12 1 (Debian))
	id 17uuJX-0006vJ-00; Fri, 27 Sep 2002 07:33:47 -0500
Received: from joern by server.localnet with local (Exim 3.35 #1 (Debian))
	id 17uuJP-0007MK-00; Fri, 27 Sep 2002 14:33:39 +0200
Subject: memory leak in gethostbyname_r
From: "Joern Heissler" <joern@heissler.de>
To: "Debian Bug Tracking System" <submit@bugs.debian.org>
X-Mailer: reportbug 1.99.49
Date: Fri, 27 Sep 2002 14:33:38 +0200
Message-Id: <E17uuJP-0007MK-00@server.localnet>
Delivered-To: submit@bugs.debian.org

Package: libc6
Version: 2.2.5-14.3
Severity: normal


-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux server 2.2.20 #5 Mon Jul 8 21:10:05 CEST 2002 i686
Locale: LANG=C, LC_CTYPE=de_DE@euro

Versions of packages libc6 depends on:
ii  libdb1-compat                 2.1.3-4    The Berkeley database routines [gl

-- no debconf information

I think I've found a memory leak in the function `gethostbyname_r'.

Example code:

#define _GNU_SOURCE
#include <netdb.h>
#include <pthread.h>

void *lookup(void *arg)
{
	char buf[8192];
	struct hostent ret,*res;
	int err;

	gethostbyname_r((char *)arg, &ret, buf, 8192, &res, &err);

	return NULL;
}

int main(void)
{
	pthread_t tid;

	do {
		pthread_create(&tid, NULL, lookup, (void *) "www.debian.org");
	} while (!pthread_join(tid, NULL));
	
	return 0;
}

I compile the code like this:
gcc -Wall -O2 -o bug bug.c -lpthread

I've found 3 ways to avoid the memory leak in this code:
- compile it with -static
- comment out gethostbyname_r()
- don't create a new thread before calling gethostbyname_r() ->
    for(;;) lookup("www.debian.org");

Every thread can leak memory only once, afaics.

Using dynamically allocated memory for `buf' and `ret' doesn't change
anything.

Regards
Joern Heissler



---------------------------------------
Received: (at 162584-done) by bugs.debian.org; 17 Jul 2004 09:27:28 +0000
>From gotom@debian.or.jp Sat Jul 17 02:27:28 2004
Return-path: <gotom@debian.or.jp>
Received: from omega.webmasters.gr.jp (webmasters.gr.jp) [218.44.239.78] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1BllTc-00087A-00; Sat, 17 Jul 2004 02:27:28 -0700
Received: from omega.webmasters.gr.jp (localhost [127.0.0.1])
	by webmasters.gr.jp (Postfix) with ESMTP
	id 0A566DEB80; Sat, 17 Jul 2004 18:27:28 +0900 (JST)
Date: Sat, 17 Jul 2004 18:27:28 +0900
Message-ID: <81zn5zasqn.wl@omega.webmasters.gr.jp>
From: GOTO Masanori <gotom@debian.or.jp>
To: "Joern Heissler" <joern@heissler.de>, 162584-done@bugs.debian.org
Subject: Re: Bug#162584: memory leak in gethostbyname_r
In-Reply-To: <E17uuJP-0007MK-00@server.localnet>
References: <E17uuJP-0007MK-00@server.localnet>
User-Agent: Wanderlust/2.9.9 (Unchained Melody) SEMI/1.14.3 (Ushinoya)
 FLIM/1.14.3 (=?ISO-8859-4?Q?Unebigory=F2mae?=) APEL/10.3 Emacs/21.2
 (i386-debian-linux-gnu) MULE/5.0 (SAKAKI)
MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya")
Content-Type: text/plain; charset=US-ASCII
Delivered-To: 162584-done@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

Hi,

At Fri, 27 Sep 2002 14:33:38 +0200,
Joern Heissler wrote:
> Package: libc6
> Version: 2.2.5-14.3
> Severity: normal

> I think I've found a memory leak in the function `gethostbyname_r'.
> 
> Example code:
> 
> #define _GNU_SOURCE
> #include <netdb.h>
> #include <pthread.h>
> 
> void *lookup(void *arg)
> {
> 	char buf[8192];
> 	struct hostent ret,*res;
> 	int err;
> 
> 	gethostbyname_r((char *)arg, &ret, buf, 8192, &res, &err);
> 
> 	return NULL;
> }
> 
> int main(void)
> {
> 	pthread_t tid;
> 
> 	do {
> 		pthread_create(&tid, NULL, lookup, (void *) "www.debian.org");
> 	} while (!pthread_join(tid, NULL));
> 	
> 	return 0;
> }
> 
> I compile the code like this:
> gcc -Wall -O2 -o bug bug.c -lpthread
> 
> I've found 3 ways to avoid the memory leak in this code:
> - compile it with -static
> - comment out gethostbyname_r()
> - don't create a new thread before calling gethostbyname_r() ->
>     for(;;) lookup("www.debian.org");
> 
> Every thread can leak memory only once, afaics.
> 
> Using dynamically allocated memory for `buf' and `ret' doesn't change
> anything.

Thanks for your report.  In glibc 2.3.2.ds1-13, I confirmed this bug
was fixed with both nptl and linuxthreads.  I close this bug.

Regards,
-- gotom





Reply to: