From: | "Thomas Hallgren" <thhal(at)mailblocks(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: bug in GUC |
Date: | 2004-06-24 09:06:25 |
Message-ID: | cbe5q2$kpa$1@news.hub.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-docs pgsql-hackers pgsql-patches |
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" <alvherre(at)dcc(dot)uchile(dot)cl> wrote in message
news:20040624052712(dot)GA7158(at)dcc(dot)uchile(dot)cl(dot)(dot)(dot)
> 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 (<alvherre[a]dcc.uchile.cl>)
> "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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-06-24 14:02:08 | Re: bug in GUC |
Previous Message | Thomas Hallgren | 2004-06-24 06:49:21 | Re: bug in GUC |
From | Date | Subject | |
---|---|---|---|
Next Message | Jeroen T. Vermeulen | 2004-06-24 09:20:39 | Re: PREPARE and transactions |
Previous Message | Richard Huxton | 2004-06-24 07:22:17 | Re: PREPARE and transactions |
From | Date | Subject | |
---|---|---|---|
Next Message | Gavin Sherry | 2004-06-24 10:31:51 | Include tablespace information in psql \d footers |
Previous Message | Thomas Hallgren | 2004-06-24 06:49:21 | Re: bug in GUC |