Return-Path: owner-postman Received: from localhost.Berkeley.EDU (localhost.Berkeley.EDU [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.10/8.6.3) with SMTP id JAA24980 for postgres-redist; Thu, 13 Jul 1995 09:13:17 -0700 Resent-From: POSTGRES mailing list Resent-Message-Id: <199507131613.JAA24980@nobozo.CS.Berkeley.EDU> X-Authentication-Warning: nobozo.CS.Berkeley.EDU: Host localhost.Berkeley.EDU didn't use HELO protocol Sender: owner-postman@postgres.Berkeley.EDU X-Return-Path: owner-postman Received: from obelix.icce.rug.nl (root@obelix.icce.rug.nl [129.125.14.129]) by nobozo.CS.Berkeley.EDU (8.6.10/8.6.3) with ESMTP id JAA24970 for ; Thu, 13 Jul 1995 09:13:15 -0700 Received: from basil.icce.rug.nl (uubasil@localhost) by obelix.icce.rug.nl (8.6.12/8.6.9) with UUCP id SAA06526; Thu, 13 Jul 1995 18:07:52 +0200 Received: by basil.icce.rug.nl (NX5.67e/R&A-1.5(basil#5)) id AA01107; Wed, 12 Jul 95 18:50:11 +0200 Message-Id: <9507121650.AA01107@basil.icce.rug.nl> Content-Type: text/plain Mime-Version: 1.0 (NeXT Mail 3.3 v118.2) Received: by NeXT.Mailer (1.118.2) From: "Tom R.Hageman" Date: Wed, 12 Jul 95 18:50:05 +0200 To: rp2y@methi.ndim.edrc.cmu.edu Subject: Re: putenv in postmaster.c Cc: postgres@postgres.Berkeley.EDU, Shreeniwas N Sapre References: <199507101710.KAA06819@nobozo.CS.Berkeley.EDU> Resent-To: postgres-redist@postgres.Berkeley.EDU Resent-Date: Thu, 13 Jul 95 09:13:17 -0700 Resent-XMts: smtp Robert Patrick wrote: > [Shreeniwas N Sapre wrote:] > > The use of putenv in postmaster.c (sample below) has crashed > > postmaster on our system (DGUX 5.4R2.10). The symptom is its inability > > to find "template1" after servicing the first 2 or 3 requests. My > > diagnosis is the use of envEntry ( which is on stack) for putenv > > causing corrupted environment entries, as putenv keeps a pointer to > > the string and not a copy of the string. This problem surfaced after > > we made a few changes (unrelated to this problem) to postmaster. We > > have made envEntry as "static" as a solution. > > [code sample munched] > > First, I'm confused by the code that you posted, this obviously isn't > right since the memory allocated for envEntry is allocated on the > stack when this function is called and released when the function > returns. I am assuming that this is the "bad" example. > > Second, I'm not sure where you got this code because both Postgres V4.2 > and Postgres95 actually declare envEntry as an array of pointers and > call calloc() to allocate the memory (which is probably a cleaner > solution that using a "static" array of character arrays). > > BackendStartup looks like this in Postgres V4.2: > > BackendStartup(packet, port) > ... > { > ... > char *envEntry[4]; > > > for (i = 0; i < 4; ++i) { > envEntry[i] = calloc(2 * ARGV_SIZE, 1); > } > sprintf(envEntry[0], "POSTPORT=%d", PostPortName); > putenv(envEntry[0]); > > ... > } Well, I've got the original postgres 4.2 lying around and it indeed uses the method as described by the first poster. There has been a patch (I think) by aoki that changed this to use calloc()ed strings. The disadvantage of the new method, at least the way it is implemented now, is that it introduces a memory leak. Which is rather a nuisance in a potentially never-ending process like the postmaster. (but then, I'm sure it is not the only one... ) -- __/__/__/__/ Tom Hageman [NeXTmail/Mime OK] __/ __/_/ IC Group (work) __/__/__/ "...to baldly go where no one has gone before." __/ _/_/ -- star trek TNG ============================================================================== To add/remove yourself to/from the POSTGRES mailing list: send mail with the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU". If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and a human will deal with it. DO NOT post to the "postgres" mailing list. ============================================================================== URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres/