cleanup psql memory handling

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: cleanup psql memory handling
Date: 2004-01-23 20:04:33
Message-ID: 878yjyxwha.fsf@mailbox.samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
psql-mem-handling-1.patch text/x-patch 23.3 KB

Browse pgsql-patches by date

  From Date Subject
Next Message Neil Conway 2004-01-23 20:20:31 Re: 7.5 change documentation
Previous Message Jan Wieck 2004-01-23 20:03:59 Re: pltcl - "Cache lookup for attribute" error - version