dbTalk Databases Forums  

[BUGS] BUG #2741: Double-free on error in ECPGconnect

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #2741: Double-free on error in ECPGconnect in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Peter Harris
 
Posts: n/a

Default [BUGS] BUG #2741: Double-free on error in ECPGconnect - 11-10-2006 , 12:18 AM







The following bug has been logged online:

Bug reference: 2741
Logged by: Peter Harris
Email address: pharris (AT) csl (DOT) co.uk
PostgreSQL version: 8.1 and earlier
Operating system: Linux
Description: Double-free on error in ECPGconnect
Details:

When using more than one database connection with ECPG, you might have
obtained and freed blocks of data on one connection before trying to open
the other.
If the second connection fails, ECPGraise will be called and call
ECPGfree_auto_mem. This can cause an invalid free() of a pointer you've
already freed.
==========================================
/*
demonstrate "double free on connection error" bug in libecpg

build:
ecpg bug.pgc
gcc -o bug bug.c -lecpg

test:
valgrind ./bug

to show what happens if you do ECPGclear_auto_mem, gcc -D FIX
*/
#ifdef FIX
extern void ECPGclear_auto_mem(void);
#endif

EXEC SQL INCLUDE sqlca;
EXEC SQL WHENEVER SQLERROR CONTINUE;

int main(int argc, char **argv)
{
EXEC SQL BEGIN DECLARE SECTION;
const char **anything=NULL;
EXEC SQL END DECLARE SECTION;

/* first connection, should be OK */
EXEC SQL CONNECT TO template1 AS ok_cnx;

/* get some stuff, doesn't matter what */
EXEC SQL AT ok_cnx SELECT datname INTO :anything FROM pg_database;

/* free it */
free(anything);

#ifdef FIX
ECPGclear_auto_mem();
#endif

/* second connection to nonexistent database */
EXEC SQL CONNECT TO no_such_database AS crash_cnx;

return 0;
}
==============================================
ECPGconnect should call ECPGclear_auto_mem, just as
ECPGdo does. Patch will be posted soon...

Peter Harris

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.