not checking value returned from palloc?

Поиск
Список
Период
Сортировка
От Mark Dilger
Тема not checking value returned from palloc?
Дата
Msg-id dvkhv5$sf7$1@news.hub.org
обсуждение исходный текст
Ответы Re: not checking value returned from palloc?  (Peter Eisentraut <peter_e@gmx.net>)
Re: not checking value returned from palloc?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
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
Дата:
Сообщение: Re: [pgsql-advocacy] PostgreSQL Anniversary Proposals -- Important Update
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: not checking value returned from palloc?