This patch makes some of the memory manipulation performed by psql a
little more sane. Some parts of the code was using a static function
xmalloc() that did safe memory allocation (where "safe" means "bail
out on OOM"), but most of it was just invoking calloc() or malloc()
directly. So I moved xmalloc() and xmalloc_zero() to be public (within
psql) functions, and added a new xcalloc(), then changed (almost) all
the call sites of calloc(), malloc(), and strdup() to use the safer
versions (there was previously an xstrdup(), but there were still some
call sites that used strdup() directly).
Most of the call sites of malloc() et al. that I replaced tried to do
something "intelligent" if OOM occurred, like returning NULL or false
depending on the function. ISTM that is just a waste of cycles, and
may actually cause more problems: for example, this practise might
result in returning a NULL pointer to a caller that isn't expecting
one -- so OOM would result in a core dump rather than an error message
& a clean exit. So I just ripped all that out and replaced it with the
new functions, which always bail out on OOM.
Unless anyone objects, I intend to apply this within 24 hours.
pgsql-patches by date
|Next:||From: Neil Conway||Date: 2004-01-23 20:20:31|
|Subject: Re: 7.5 change documentation|
|Previous:||From: Jan Wieck||Date: 2004-01-23 20:03:59|
|Subject: Re: pltcl - "Cache lookup for attribute" error - version|