Re: fix a bogus line in dynahash.c - Mailing list pgsql-patches

From Neil Conway
Subject Re: fix a bogus line in dynahash.c
Date
Msg-id 4293E7E1.3060001@samurai.com
Whole thread Raw
In response to fix a bogus line in dynahash.c  ("Qingqing Zhou" <zhouqq@cs.toronto.edu>)
List pgsql-patches
Qingqing Zhou wrote:
> On a separate matter, can anyone please explain me how this piece of code
> works:
>
>     /* no free elements.  allocate another chunk of buckets */
>     if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR))
>      return NULL; /* out of memory */
>
> element_alloc() in fact uses MemoryContextAlloc() stuff.

Well, element_alloc() uses the hash table's alloc function pointer. In
theory, that could be malloc() or anything else, although I notice this
abstraction is not consistently maintained (e.g. dir_realloc assumes
pfree() is sufficient to free an allocation).

I think it would be a good idea to change dynahash.c to assume that the
hash table's allocation function will elog(ERROR) on out-of-memory, so
its return value will always be non-NULL. This would allow for a bunch
of code to be simplified.

-Neil

pgsql-patches by date:

Previous
From: Neil Conway
Date:
Subject: Re: [PATCH] pg_autovacuum commandline password hiding.
Next
From: Tom Lane
Date:
Subject: Re: fix a bogus line in dynahash.c