Re: [BUG] CRASH: ECPGprepared_statement() and ECPGdeallocate_all() when connection is NULL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Nishant Sharma <nishant(dot)sharma(at)enterprisedb(dot)com>, Shruthi Gowda <gowdashru(at)gmail(dot)com>, Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUG] CRASH: ECPGprepared_statement() and ECPGdeallocate_all() when connection is NULL
Date: 2026-05-06 14:58:27
Message-ID: 771392.1778079507@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Attached is a patch with the fix, courtesy of claude. It's a slight
> behaviour change:

Yeah. So we could either do something like this, or say that the
test case is buggy and needs to provide its own mutexes, per the
existing comment

- * if no connection in TSD for this thread, get the global default
- * connection and hope the user knows what they're doing (i.e. using
- * their own mutex to protect that connection from concurrent accesses

On the whole I think I favor the behavior change. We might get some
complaints, but it just seems a lot safer to redefine it like this.

Either way, it seems like some documentation adjustments are called
for.

As far as the patch itself goes, I'd be inclined to pull the
preparatory step

ecpg_pthreads_init(); /* ensure actual_connection_key is valid */

into the new ecpg_default_connection() subroutine, especially since
its proposed comment doesn't mention that prerequisite.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-05-06 15:02:35 Re: pgindent versus struct members and typedefs
Previous Message Nathan Bossart 2026-05-06 14:54:54 Re: Prepping for annual pgindent run