Fix error in ECPG while connection handling

From: Jeevan Ladhe <jeevan(dot)ladhe(at)enterprisedb(dot)com>
To: PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org>
Subject: Fix error in ECPG while connection handling
Date: 2018-03-12 08:07:21
Message-ID: CAOgcT0Pnh8UUGYke16At+Fy77nq2Wb6aZFzhJ8nzONKLuO=EYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I came across following error while working on ecpg client program.

$ install/bin/ecpg ecpg_connection_ptr.pgc
ecpg_connection_ptr.pgc:26: ERROR: AT option not allowed in WHENEVER
statement

I have attached simple ecpg program 'ecpg_connection_ptr_issue.pgc' that
reproduces the above issue.

After doing some investigation I could see that, in preproc.y, in rule of
'ClosePortalStmt', function output_statement() is called, which in turn
frees
the connection pointer. Here is the relevant trailing snippet from the
output_statement() function.

whenever_action(whenever_mode | 2);
free(stmt);
if (connection != NULL)
free(connection);
}

Now, when the ecpg parses following statement using rule 'ECPGWhenever':
EXEC SQL WHENEVER SQLERROR CONTINUE;
it checks if the connection is set, if it is then throws an error as below:

if (connection)
mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER
statement");

Now, ideally the connection would have been null here, but, as the
'ClosePortalStmt'
rule freed the connection but did not set it to NULL, it still sees that
there
is a connection(which is actually having garbage in it) and throws an error.

I see similarly there are other places, which are freeing this global
connection
but not setting to NULL, and all those should be fixed. I have attached a
patch
ecpg_connection_ptr_issue_fix.patch to fix these places.

Regards,
Jeevan Ladhe

Attachment Content-Type Size
ecpg_connection_ptr_issue_fix.patch application/octet-stream 725 bytes
ecpg_connection_ptr_issue.pgc application/octet-stream 619 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anthony Bykov 2018-03-12 08:08:21 Re: Transform for pl/perl
Previous Message Etsuro Fujita 2018-03-12 07:55:03 Re: [HACKERS] Another oddity in handling of WCO constraints in postgres_fdw