Re: Do we want a xmalloc or similar function in the Backend? - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Do we want a xmalloc or similar function in the Backend?
Date
Msg-id CA+TgmoY1obwUcG6obniKRahB1QZcF1cQQhrN=_nZRjT4dgiPow@mail.gmail.com
Whole thread Raw
In response to Do we want a xmalloc or similar function in the Backend?  (Andres Freund <andres@2ndquadrant.com>)
Responses Re: Do we want a xmalloc or similar function in the Backend?  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
On Tue, Jun 19, 2012 at 10:17 AM, Andres Freund <andres@2ndquadrant.com> wrote:
> There are 70+ calls of malloc in the backend in the form of
>
> type* foo = malloc(sizeof(...));
> if(!foo)
>   elog(ERROR, "could not allocate memory");
>
> which is a bit annoying to write at times. Would somebody argue against
> introducing a function that does the above named xmalloc() or malloc_or_die()?

I can't even find 70 malloc calls in the entire backend, let alone 70
with that pattern.  Still, I don't think malloc_or_error (not die)
would be a bad idea.

But the error should definitely be written as:
                       ereport(ERROR,                                       (errcode(ERRCODE_OUT_OF_MEMORY),
                           errmsg("out of memory"))); 

...not elog.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-hackers by date:

Previous
From: Alex Hunsaker
Date:
Subject: Re: pl/perl and utf-8 in sql_ascii databases
Next
From: Andres Freund
Date:
Subject: Re: Do we want a xmalloc or similar function in the Backend?