pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Simplex <hypercube.mail@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: memory leak in libpq , definitely lost: 200 bytes in 1 blocks, indirectly lost: 2,048 bytes in 1 blocks ...
Date: Mon, 10 Oct 2016 12:38:08 +0300
Message-ID: <CAD-Qf1eLUtBOTPXyFQGW-4eEsop31tVVdZPu4kL9pbQ6tJPO8g@mail.gmail.com> (raw )
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <termios.h>
#include <time.h>
#include <stdbool.h>
#include <libpq-fe.h>
// gcc -o db_test.o -c -I/usr/include/postgresql db_test.c
// gcc -o db_test db_test.o -lpq
//-------------------------------------------------------------------------------------------------------------------------------//
int main(void)
{
PGconn *pg_conn = NULL;
PGresult *res = NULL;
ConnStatusType status = CONNECTION_BAD;
const char *conninfo = "host = 192.168.0.20 port = 20000 dbname = dbtest
user = postgres password = postgres application_name = app-test";
if((pg_conn = PQconnectdb(conninfo)) != NULL)
{
fprintf(stdout, "\n -CP00- \n");
if(PQstatus(pg_conn) != CONNECTION_OK)
{
fprintf(stdout, "\n -CP01-[%d]- \n", PQstatus(pg_conn));
do
{
sleep(2);
PQreset(pg_conn);
status = PQstatus(pg_conn);
fprintf(stdout, "\n -CP02-[%d]- \n", status);
}
while(status != CONNECTION_OK);
}
fprintf(stdout, "\n -CP03-[%d]- \n", PQstatus(pg_conn));
res = PQexec(pg_conn, "SELECT 1 AS a");
PQclear(res); res = NULL;
PQfinish(pg_conn); pg_conn = NULL;
}
return(0);
}
//-------------------------------------------------------------------------------------------------------------------------------//
STEP_1_ON-THE-APP-SERVER - compile the application
gcc -o db_test.o -c -I/usr/include/postgresql db_test.c
gcc -o db_test db_test.o -lpq
{
STEP_2_ON-THE-DB-SERVER - stop PostgreSQL
sudo service postgresql stop
STEP_3_ON-THE-APP-SERVER - run the application
valgrind --leak-check=full --show-reachable=yes --leak-resolution=high -v
./db_test > ./log.log 2>&1
STEP_4_ON-THE-DB-SERVER - wait [N] seconds (N is a random chosen number
between 10-3000) and start PostgreSQL
} Repeat several times to get the leak
Valgrind options:
--22352-- --leak-check=full
--22352-- --show-reachable=yes
--22352-- --leak-resolution=high
--22352-- -v
--22352-- Contents of /proc/version:
--22352-- Linux version 4.4.0-36-generic (buildd@lcy01-01) (gcc version
5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) ) #55-Ubuntu SMP Thu Aug 11
18:01:55 UTC 2016
--22352--
==18777== 2,048 bytes in 1 blocks are indirectly lost in loss record 282 of
290
==18777== at 0x4C2DB8F: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18777== by 0x4E4A1C9: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E4A87C: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E541A4: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E48396: PQconnectPoll (in
/usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E488ED: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E495C7: PQreset (in
/usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4009FB: main (in
/home/puffy/bkserver/pg_db_test_bug00/db_test)
==18777== 2,248 (200 direct, 2,048 indirect) bytes in 1 blocks are
definitely lost in loss record 283 of 290
==18777== at 0x4C2DB8F: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18777== by 0x4E4A5DC: PQmakeEmptyPGresult (in
/usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E54161: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E48396: PQconnectPoll (in
/usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E488ED: ??? (in /usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4E495C7: PQreset (in
/usr/lib/x86_64-linux-gnu/libpq.so.5.8)
==18777== by 0x4009FB: main (in
/home/puffy/bkserver/pg_db_test_bug00/db_test)
==18777== LEAK SUMMARY:
==18777== definitely lost: 200 bytes in 1 blocks
==18777== indirectly lost: 2,048 bytes in 1 blocks
==18777== possibly lost: 0 bytes in 0 blocks
==18777== still reachable: 93,928 bytes in 2,899 blocks
==18777== suppressed: 0 bytes in 0 blocks
==18777==
==18777== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==18777== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
db_test.c (text/x-csrc, 1.4K) download
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <termios.h>
#include <time.h>
#include <stdbool.h>
#include <libpq-fe.h>
// gcc -o db_test.o -c -I/usr/include/postgresql db_test.c
// gcc -o db_test db_test.o -lpq
//-------------------------------------------------------------------------------------------------------------------------------//
int main(void)
{
PGconn *pg_conn = NULL;
PGresult *res = NULL;
ConnStatusType status = CONNECTION_BAD;
const char *conninfo = "host = 192.168.0.20 port = 20000 dbname = dbtest user = postgres password = postgres application_name = app-test";
if((pg_conn = PQconnectdb(conninfo)) != NULL)
{
fprintf(stdout, "\n -CP00- \n");
if(PQstatus(pg_conn) != CONNECTION_OK)
{
fprintf(stdout, "\n -CP01-[%d]- \n", PQstatus(pg_conn));
do
{
sleep(2);
PQreset(pg_conn);
status = PQstatus(pg_conn);
fprintf(stdout, "\n -CP02-[%d]- \n", status);
}
while(status != CONNECTION_OK);
}
fprintf(stdout, "\n -CP03-[%d]- \n", PQstatus(pg_conn));
res = PQexec(pg_conn, "SELECT 1 AS a");
PQclear(res); res = NULL;
PQfinish(pg_conn); pg_conn = NULL;
}
return(0);
}
//-------------------------------------------------------------------------------------------------------------------------------//
view thread (3+ messages) latest in thread
Message-ID: <CAD-Qf1eLUtBOTPXyFQGW-4eEsop31tVVdZPu4kL9pbQ6tJPO8g@mail.gmail.com>
Permalink: ../CAD-Qf1eLUtBOTPXyFQGW-4eEsop31tVVdZPu4kL9pbQ6tJPO8g@mail.gmail.com/
Also on: postgresql.org/message-id/CAD-Qf1eLUtBOTPXyFQGW-4eEsop31tVVdZPu4kL9pbQ6tJPO8g@mail.gmail.com
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: hypercube.mail@gmail.com
Subject: Re: memory leak in libpq , definitely lost: 200 bytes in 1 blocks, indirectly lost: 2,048 bytes in 1 blocks ...
In-Reply-To: <CAD-Qf1eLUtBOTPXyFQGW-4eEsop31tVVdZPu4kL9pbQ6tJPO8g@mail.gmail.com>
References: <CAD-Qf1eLUtBOTPXyFQGW-4eEsop31tVVdZPu4kL9pbQ6tJPO8g@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox