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 > ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly