Thread: BUG #6366: ECPG connection Memory Leak when using Host Variables

BUG #6366: ECPG connection Memory Leak when using Host Variables

From
li_gang02@sina.com
Date:
The following bug has been logged on the website:

Bug reference:      6366
Logged by:          Gang, Li
Email address:      li_gang02@sina.com
PostgreSQL version: 9.1.1
Operating system:   openSUSE 11.4 (AMD CPU, x86_64bits)
Description:=20=20=20=20=20=20=20=20

Hallo,

/*
** PostgreSQL bug on ECPG connection when using Host Variables
**
**  Reference:
**=20=20=20=20=20
http://doxygen.postgresql.org/interfaces_2ecpg_2ecpglib_2misc_8c_source.htm=
l#l00512
**  File:
**      postgresql-9.1.1/src/interfaces/ecpg/ecpglib/misc.c
**  Description:
**      Function ECPGset_var() will call calloc() to allocate memory for a
new node.
**      And all nodes are appended to a static global list named 'static
struct var_list'.
**      But the list memory is never been freed with free() in any case, and
no relative function
**          is available for me. After ECPG connection is disconnected,
ECPGset_var() resultes
**          in memory leak (TotalSize =3D n * sizeof(struct var_list), wher=
e n
is maxium
**          of Host Variables used in a DB Connection).
**
**  Bug Fixing:
**      A new function should be added, details as folloging
**          void ECPGfree_var()
**          {
**              struct var_list *workPtr =3D ivlist;
**              while (NULL !=3D workPtr)
**              {
**                  ivlist =3D (struct var_list *)ivlist->next;
**                  free(workPtr);
**                  workPtr =3D ivlist;
**              }
**
**              ivlist =3D NULL;
**          }
**
**      Also, above function ECPGfree_var() should be called after all SQL
queries, and before
**      current ECPG connection is going to be closed.
*/


Best Regards,

Gang, Li

Re: BUG #6366: ECPG connection Memory Leak when using Host Variables

From
Michael Meskes
Date:
> ** PostgreSQL bug on ECPG connection when using Host Variables

Thanks for bringing this up. I just commited a fix into our git.

> **          in memory leak (TotalSize =3D n * sizeof(struct var_list), wh=
ere n
> is maxium
> **          of Host Variables used in a DB Connection).

The actual number is quite a bit lower because only variables used in DECLA=
RE
statements directly get stored in that list.

> **  Bug Fixing:
> **      A new function should be added, details as folloging

I integrated this into the connection closing code.=20

Michael
--=20
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
Jabber: michael.meskes at googlemail dot com
VfL Borussia! For=C3=A7a Bar=C3=A7a! Go SF 49ers! Use Debian GNU/Linux, Pos=
tgreSQL