X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3AA3DD1B175 for ; Thu, 24 Jun 2004 06:13:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14174-10 for ; Thu, 24 Jun 2004 09:13:17 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 815C0D1B170 for ; Thu, 24 Jun 2004 06:13:14 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i5O9DEQC021677 for ; Thu, 24 Jun 2004 09:13:14 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i5O9AQkE021294 for pgsql-hackers@postgresql.org; Thu, 24 Jun 2004 09:10:26 GMT From: "Thomas Hallgren" X-Newsgroups: comp.databases.postgresql.hackers Subject: Re: bug in GUC Date: Thu, 24 Jun 2004 11:06:25 +0200 Organization: Hub.Org Networking Services Lines: 67 Message-ID: References: <20040624052712.GA7158@dcc.uchile.cl> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 To: pgsql-hackers@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=PRIORITY_NO_NAME X-Spam-Level: X-Archive-Number: 200406/851 X-Sequence-Number: 55401 Rather than clutter the code with the same ereport over and over again (I count 12 malloc's in guc.c alone), I'd like something like this: void* malloc_or_fail(int elevel, size_t sz) { void* result; if(sz < 1) /* * Make sure we have something that can be passed to free() even * when the size is zero. */ sz = 1; result = malloc(sz); if(result == NULL) { ereport(elevel, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); /* Oops, ereport returned! Who called us with elevel < ERROR? */ exit(EXIT_FAILURE); } return result; } void* malloc_or_error(size_t sz) { return malloc_or_fail(ERROR, sz); } void* malloc_or_fatal(size_t sz) { return malloc_or_fail(FATAL, sz); } I search the code but the only thing I find that comes close is pq_malloc. But that's a different thing altogether since it doesn't use ereport. I'm sure I missed something somewhere but if not, perhaps the above functions would make sense? If so, what's the best name for them and where should they reside? Kind regards, Thomas Hallgren "Alvaro Herrera" wrote in message news:20040624052712.GA7158@dcc.uchile.cl... > Hackers, > > I think there a bug in the GUC mechanism. The custom variables patch > added several malloc() and a strdup() call, and they are never checked > for an out of memory condition. > > -- > Alvaro Herrera () > "El que vive para el futuro es un iluso, y el que vive para el pasado, > un imbécil" (Luis Adler, "Los tripulantes de la noche") > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >