Re: Do we want a xmalloc or similar function in the Backend?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Do we want a xmalloc or similar function in the Backend?
Date: 2012-06-19 14:38:56
Message-ID: 12259.1340116736@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> 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()?

99% of the time, you should be using palloc if that's the behavior you
want. I think most of the malloc calls are in places where we want a
bit more control over the error response.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2012-06-19 14:41:17 Re: sortsupport for text
Previous Message Tom Lane 2012-06-19 14:30:59 Re: [PATCH 10/16] Introduce the concept that wal has a 'origin' node