cleanup psql memory handling - Mailing list pgsql-patches

From Neil Conway
Subject cleanup psql memory handling
Date
Msg-id 878yjyxwha.fsf@mailbox.samurai.com
Whole thread Raw
List pgsql-patches
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.

-Neil


Attachment

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: pltcl - "Cache lookup for attribute" error - version 2
Next
From: Jan Wieck
Date:
Subject: Re: pltcl - "Cache lookup for attribute" error - version