Re: Minor cleanup for search path cache

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Minor cleanup for search path cache
Date: 2024-01-02 05:12:22
Message-ID: 9f15e056-dea1-4b16-94de-853516ed6ad8@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Zhang Mingli
www.hashdata.xyz
On Jan 2, 2024 at 05:38 +0800, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, wrote:
> I happened to notice that there is a not-quite-theoretical crash
> hazard in spcache_init(). If we see that SPCACHE_RESET_THRESHOLD
> is exceeded and decide to reset the cache, but then nsphash_create
> fails for some reason (perhaps OOM), an error will be thrown
> leaving the SearchPathCache pointer pointing at already-freed
> memory. Next time through, we'll try to dereference that dangling
> pointer, potentially causing SIGSEGV, or worse we might find a
> value less than SPCACHE_RESET_THRESHOLD and decide that the cache
> is okay despite having been freed.
>
> The fix of course is to make sure we reset the pointer variables
> *before* the MemoryContextReset.
>
> I also observed that the code seems to have been run through
> pgindent without fixing typedefs.list, making various places
> uglier than they should be.
>
> The attached proposed cleanup patch fixes those things and in
> passing improves (IMO anyway) some comments. I assume it wasn't
> intentional to leave two copies of the same comment block in
> check_search_path().
>
> regards, tom lane
>
Only me?

zml(at)localhashdata postgres % git apply minor-search-path-cache-cleanup.patch
error: patch failed: src/backend/catalog/namespace.c:156
error: src/backend/catalog/namespace.c: patch does not apply
error: patch failed: src/tools/pgindent/typedefs.list:2479
error: src/tools/pgindent/typedefs.list: patch does not apply

I’m in commit 9a17be1e24 Allow upgrades to preserve the full subscription's state

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-01-02 05:20:51 Re: Minor cleanup for search path cache
Previous Message Amit Kapila 2024-01-02 05:05:59 Re: Track in pg_replication_slots the reason why slots conflict?