public inbox for [email protected]
help / color / mirror / Atom feedFrom: Thomas Hallgren <[email protected]>
To: [email protected]
Subject: Re: bug in GUC
Date: Thu, 24 Jun 2004 11:06:25 +0200
Message-ID: <[email protected]> (raw)
References: <[email protected]>
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" <[email protected]> wrote in message
news:[email protected]...
> 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
>
view thread (10+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: bug in GUC
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox