Re: bug in GUC - Mailing list pgsql-hackers

From Thomas Hallgren
Subject Re: bug in GUC
Date
Msg-id cbe5q2$kpa$1@news.hub.org
Whole thread Raw
In response to bug in GUC  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Responses Re: bug in GUC
List pgsql-hackers
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        *
whenthe 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@dcc.uchile.cl> 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 (<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
>



pgsql-hackers by date:

Previous
From: Richard Huxton
Date:
Subject: Re: PREPARE and transactions
Next
From: "Jeroen T. Vermeulen"
Date:
Subject: Re: PREPARE and transactions