From owner-freebsd-hackers Wed Sep 17 01:39:24 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id BAA00240 for hackers-outgoing; Wed, 17 Sep 1997 01:39:24 -0700 (PDT) Received: from citadel.cdsec.com (citadel.cdsec.com [192.96.22.18]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id BAA00222 for ; Wed, 17 Sep 1997 01:39:19 -0700 (PDT) Received: (from nobody@localhost) by citadel.cdsec.com (8.8.5/8.6.9) id KAA09655; Wed, 17 Sep 1997 10:44:15 +0200 (SAT) Received: by citadel via recvmail id 9653; Wed Sep 17 10:44:00 1997 by gram.cdsec.com (8.8.5/8.8.5) id KAA02083; Wed, 17 Sep 1997 10:06:48 +0200 (SAT) From: Graham Wheeler Message-Id: <199709170806.KAA02083@cdsec.com> Subject: Re: Memory leak in getservbyXXX? To: phk@critter.freebsd.dk (Poul-Henning Kamp) Date: Wed, 17 Sep 1997 10:06:47 +0200 (SAT) Cc: hackers@freebsd.org In-Reply-To: <7153.874473906@critter.freebsd.dk> from "Poul-Henning Kamp" at Sep 17, 97 07:25:06 am X-Mailer: ELM [version 2.4 PL25-h4.1] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk (I've stopped cc-ing to freebsd-bugs on the assumption that the bug is mine). Unfortunately the problem hasn't gone away. This morning the program was spinning again, along with about ten child processes. This is really weird, especially as all the child processes do is a gethostbyaddr(), write the result to a (pipe) file descriptor, and exit. Here is some code, if this sheds any light (these are all virtual methods): int ChildProcess::Spawn() { if (ChildManager::Register(this) >= 0) { if ((pid = fork()) == 0) { exit(Run()); } else if (pid>0) { state = Running; starttime = Time(); return 0; } } state = Failed; return -1; } // PipeChildProcess inherits from ChildProcess int PipeChildProcess::Spawn() { if (socketpair(AF_UNIX, SOCK_STREAM, 0, pfd) < 0) { state = Failed; return -1; } int rtn = ChildProcess::Spawn(); if (rtn < 0) close(pfd[0]); else pipefd = pfd[0]; close(pfd[1]); return rtn; } int PipeChildProcess::Run() { close(pfd[0]); pipefd = pfd[1]; // set standard descriptors to be pipe for (int i = 0; i < 3; i++) if (i != pipefd) if (dup2(pipefd, i) < 0) return -1; return Exec(); } // DNSLookupProcess inherits from PipeChildProcess int DNSLookupProcess::Exec() { unsigned char *cp = (unsigned char *)&addr; printf("%c%c%c%c", cp[0], cp[1], cp[2], cp[3]); struct in_addr a; a.s_addr = addr; struct hostent *h = gethostbyaddr((char*)&a, 4, AF_INET); if (h) { printf("%s", h->h_name); return 0; } return (-1); } -- Dr Graham Wheeler E-mail: gram@cdsec.com Citadel Data Security Phone: +27(21)23-6065/6/7 Internet/Intranet Network Specialists Mobile: +27(83)-253-9864 Firewalls/Virtual Private Networks Fax: +27(21)24-3656 Data Security Products WWW: http://www.cdsec.com/