not checking value returned from palloc?

Поиск
Список
Период
Сортировка
Искать
От
Mark Dilger
Тема
not checking value returned from palloc?
Дата
Msg-id
dvkhv5$sf7$1@news.hub.org
Список
Дерево обсуждения
not checking value returned from palloc? Mark Dilger <pgsql@markdilger.com>
Re: not checking value returned from palloc? Peter Eisentraut <peter_e@gmx.net>
Re: not checking value returned from palloc? Mark Dilger <pgsql@markdilger.com>
Re: not checking value returned from palloc? Alvaro Herrera <alvherre@commandprompt.com>
Re: not checking value returned from palloc? Bruce Momjian <pgman@candle.pha.pa.us>
Re: not checking value returned from palloc? Neil Conway <neilc@samurai.com>
Re: not checking value returned from palloc? Tom Lane <tgl@sss.pgh.pa.us>
Looking through the postgresql source code, I notice that there are many places 
were palloc is used but the return value is not checked to see if it is null. 
There are a few places such as:
        if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count +	strlen(nsymbol))))            ereport(ERROR,                    (errcode(ERRCODE_OUT_OF_MEMORY),                     errmsg("out of memory")));

(taken from src/backend/utils/adt/cash.c), but at least within the that same 
directory most occurrences of palloc are not checked.

Is this sloppy programming, or is there an automagical thing going on with 
#defines that I'm just not seeing?

If it is just sloppy, perhaps we could use a new define in palloc.h, such as:

#define palloc_or_die(ptr,sz) \do { \	ptr = palloc(sz); \	if (!ptr) \	{ \		ereport(ERROR, \			(errcode(ERRCODE_OUT_OF_MEMORY), \			 errmsg("Out of memory"))); \	} \} while(0);	
And then, in all places where the code does not currently check the return value 
of palloc, the code could be changed to use palloc_or_die instead.  Of course, 
I'd be happy if someone has a better name for the macro, perhaps something more 
brief?

I can go over the code "with a fine tooth comb" and replace the offending 
occurrences.  Does the community think this is a good idea?

mark

В списке pgsql-hackers по дате отправления
От: Josh Berkus
Дата:
От: Peter Eisentraut
Дата:
FAQ