Обсуждение: BUG #5607: memmory leak in ecpg

Поиск
Список
Период
Сортировка

BUG #5607: memmory leak in ecpg

От
"Marcelo Mas"
Дата:
The following bug has been logged online:

Bug reference:      5607
Logged by:          Marcelo Mas
Email address:      mmas@atg.com.uy
PostgreSQL version: 8.4.4
Operating system:   Suse 10
Description:        memmory leak in ecpg
Details:

Valgrind reports memmory leak when getting decimal data.

We created a small testcase that reproduces the problem that:

1) crates a table whith one decimal attribute
2) inserts one row.
3) executes a exec sql sentence to retrieve data from database.
4) displays data
5) dropps the table
6) disconnects
7) exits

When running with  valgrind, it reports that memmory obtained in point 3)
is not liberated.

Next follows contents of files :
decimaltest.ec whith source code,
compiletest to compile ,
and runtest to run it with valgrind,

After files contents, follows terminal output.


------ BEGIN OF decimaltest.ec --------------
#include <stdio.h>
#include <stdlib.h>
#include "pgtypes_numeric.h"

  int  show_error(char * message){
      if( sqlca.sqlcode != 0 ) {
                printf("Error %s: [%d] \n",message ,  sqlca.sqlcode );
                     printf("\nsqlcaid = %s \n", sqlca.sqlcaid );
                     printf("sqlabc = %ld \n", sqlca.sqlabc );
                     printf("sqlcode = %ld \n", sqlca.sqlcode );
                     printf("sqlerrm.sqlerrml = %d \n",
sqlca.sqlerrm.sqlerrml );
                     printf("sqlerrm.sqlerrmc = %s \n",
sqlca.sqlerrm.sqlerrmc );
                     printf("sqlerrp = %s \n", sqlca.sqlerrp );
                     printf("sqlerrd = %d \n", sqlca.sqlerrd );
                     printf("sqlwarn = %s \n", sqlca.sqlwarn );
                     printf("sqlstate = %s \n\n", sqlca.sqlstate );
                return(-1);
      }
      return(0);
 }

int main(int argc, char *argv[]) {
    EXEC SQL BEGIN DECLARE SECTION ;
    char            base_datos[100];
    char            usuario[100];
    char            contrasenia[100];
    decimal        valor;

    char            sentence[200];

    EXEC SQL END DECLARE SECTION;
    int count = 0;


    if( argc < 4) {
        printf("use : %s <database@server> <username> <password>\n", argv[0]
);
        return(-1);
    }



/*--------------------------------------------------------------------------
--
    /  connect to database

/---------------------------------------------------------------------------
-*/
    strcpy( base_datos, argv[1] );
    strcpy( usuario, argv[2] );
    strcpy( contrasenia, argv[3] );
    EXEC SQL CONNECT TO :base_datos USER :usuario / :contrasenia ;


    if( sqlca.sqlcode != 0 ) {
        printf("Error Connecting:[%d] \n", sqlca.sqlcode );
        return(-1);
    }

    printf("Connected\n" );

    sprintf(sentence, "create table testdecimal ( tdecimal
decimal(18,9));");
    EXEC SQL EXECUTE IMMEDIATE :sentence;
    if (  show_error("creting table ")!= 0 ) return(-1);
    sprintf(sentence, "insert into testdecimal values ( '12345654.32101234'
);");
    EXEC SQL EXECUTE IMMEDIATE :sentence;
    if (  show_error("inserting data ")!= 0 ) return(-1);



    /**********/
    /*  TEST  */
    /**********/
    EXEC SQL
        SELECT tdecimal into :valor from testdecimal  limit 1;


     if (  show_error("obtaining data ")!= 0 ) return(-1);

     printf("ndigits = %d \n", valor.ndigits);
     printf("weitht  = %d \n", valor.weight);
     printf("rscale  = %d \n", valor.rscale);
     printf("dscale  = %d \n", valor.dscale);
     printf("sign    = %d \n", valor.sign);
     printf("ndigits = ");
     for ( count = 0 ; count< valor.ndigits ; count++ ){
        printf("%02x ",valor.digits[count]);
     }

     printf("\n\n");


    sprintf(sentence, "drop table testdecimal;");
    EXEC SQL EXECUTE IMMEDIATE :sentence;
    if (  show_error("dropping table ")!= 0 ) return(-1);


     EXEC SQL DISCONNECT CURRENT;
     return(0);

}
------ END OF decimaltest.ec --------------

-------BEGIN OF compiletest ---------------
POSTGRE_DIR=/opt/PostgreSQL/8.4
POSTGRE_INCLUDE=$POSTGRE_DIR/include
POSTGRE_LIB=$POSTGRE_DIR/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$POSTGRE_DIR/lib
$POSTGRE_DIR/bin/ecpg decimaltest.ec
gcc -g decimaltest.c  -I$POSTGRE_INCLUDE -L$POSTGRE_LIB  -lecpg  -o
decimaltest.exe

------ END   OF compiletest ---------------

------ BEGIN OF runtest--------------------
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/PostgreSQL/8.4/lib
 valgrind --tool=memcheck --leak-check=full --leak-resolution=high
./decimaltest.exe testdatabase@server  psig psig
------ END   OF runtest--------------------

------ BEGIN OF terminal output------------
==9642== Memcheck, a memory error detector
==9642== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==9642== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==9642== Command: ./decimaltest.exe prurmmas@pruebas2:5433 psig psig
==9642==
Connected
ndigits = 17
weitht  = 7
rscale  = 9
dscale  = 9
sign    = 0
ndigits = 01 02 03 04 05 06 05 04 03 02 01 00 01 02 03 04 00

==9642==
==9642== HEAP SUMMARY:
==9642==     in use at exit: 239 bytes in 2 blocks
==9642==   total heap usage: 128 allocs, 126 frees, 42,698 bytes allocated
==9642==
==9642== 19 bytes in 1 blocks are definitely lost in loss record 1 of 2
==9642==    at 0x401CE85: calloc (vg_replace_malloc.c:418)
==9642==    by 0x4223299: pgtypes_alloc (in
/opt/PostgreSQL/8.4/lib/libpgtypes.so.3.1)
==9642==    by 0x4220583: alloc_var (in
/opt/PostgreSQL/8.4/lib/libpgtypes.so.3.1)
==9642==    by 0x4220886: PGTYPESnumeric_from_asc (in
/opt/PostgreSQL/8.4/lib/libpgtypes.so.3.1)
==9642==    by 0x4027911: ecpg_get_data (in
/opt/PostgreSQL/8.4/lib/libecpg.so.6.1)
==9642==    by 0x4023B93: ecpg_store_result (in
/opt/PostgreSQL/8.4/lib/libecpg.so.6.1)
==9642==    by 0x4025D49: ECPGdo (in
/opt/PostgreSQL/8.4/lib/libecpg.so.6.1)
==9642==    by 0x804893C: main (decimaltest.ec:71)
==9642==
==9642== LEAK SUMMARY:
==9642==    definitely lost: 19 bytes in 1 blocks
==9642==    indirectly lost: 0 bytes in 0 blocks
==9642==      possibly lost: 0 bytes in 0 blocks
==9642==    still reachable: 220 bytes in 1 blocks
==9642==         suppressed: 0 bytes in 0 blocks
==9642== Reachable blocks (those to which a pointer was found) are not
shown.
==9642== To see them, rerun with: --leak-check=full --show-reachable=yes
==9642==
==9642== For counts of detected and suppressed errors, rerun with: -v
==9642== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 43 from 8)
psig@server:~>

------ END   OF terminal output------------

Re: BUG #5607: memmory leak in ecpg

От
"Kevin Grittner"
Дата:
"Marcelo Mas" <mmas@atg.com.uy> wrote:

> Valgrind reports memmory leak when getting decimal data.

I wonder how much overlap there is between this and the patch for
fixing ECPG memory leaks offered by Zoltán Böszörményi three days
ago.  There was much discussion about the dynamic UPDATE/DELETE
WHERE CURRENT OF patch, but I don't remember any discussion of the
other patch included in the same post.

http://archives.postgresql.org/pgsql-hackers/2010-08/msg00115.php

-Kevin

Re: BUG #5607: memmory leak in ecpg

От
Michael Meskes
Дата:
I guess the described problems are identical. Feel free to apply the memleal patch.

Michael


"Kevin Grittner" <Kevin.Grittner@wicourts.gov> schrieb:

>"Marcelo Mas" <mmas@atg.com.uy> wrote:
>
>> Valgrind reports memmory leak when getting decimal data.
>
>I wonder how much overlap there is between this and the patch for
>fixing ECPG memory leaks offered by Zoltán Böszörményi three days
>ago.  There was much discussion about the dynamic UPDATE/DELETE
>WHERE CURRENT OF patch, but I don't remember any discussion of the
>other patch included in the same post.
>
>http://archives.postgresql.org/pgsql-hackers/2010-08/msg00115.php
>
>-Kevin
>
>--
>Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-bugs

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Re: BUG #5607: memmory leak in ecpg

От
"Kevin Grittner"
Дата:
[moving discussion to -hackers]

Michael Meskes <michael@fam-meskes.de> wrote:
> "Kevin Grittner" <Kevin.Grittner@wicourts.gov> schrieb:
>>"Marcelo Mas" <mmas@atg.com.uy> wrote:
>> 
>>> Valgrind reports memmory leak when getting decimal data.
>> 
>>I wonder how much overlap there is between this and the patch for
>>fixing ECPG memory leaks offered by Zoltán Böszörményi three days
>>ago.
>>http://archives.postgresql.org/pgsql-hackers/2010-08/msg00115.php
> I guess the described problems are identical. Feel free to apply
> the memleal patch.
Is someone dealing with this?  Should this be on the "PostgreSQL 9.0
Open Items" Wiki page?
-Kevin