Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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: psql-mem-handling-1.patch
Description: text/x-patch (23.3 KB)

pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group