Re: BUG #1736: endless loop in PQconnectdb - Mailing list pgsql-bugs

From Karsten Desler
Subject Re: BUG #1736: endless loop in PQconnectdb
Date
Msg-id 20050703085815.GA12605@soohrt.org
Whole thread Raw
In response to Re: BUG #1736: endless loop in PQconnectdb  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: BUG #1736: endless loop in PQconnectdb
List pgsql-bugs
* Bruce Momjian wrote:
> I think what you are seeing is that the getaddrinfo memory is placed in
> the PGconn structure that isn't freed until PQclear is called.  Does
> your test call PQclear()?

s/PQclear/PQfinish/
It does call PQclear on the result, and PQfinish on the connection.
The code is attached.

With postgres doing the dns lookup:
fubar:~# while true; do ps aux|grep -v grep|grep test; sleep 30; done
root      3245  3.6  0.2  4056 1352 pts/3    S+   10:37   0:01 ./test
root      3245  3.6  0.3  4056 1456 pts/3    S+   10:37   0:02 ./test
root      3245  3.7  0.3  4184 1560 pts/3    S+   10:37   0:03 ./test
root      3245  3.7  0.3  4312 1668 pts/3    R+   10:37   0:04 ./test
root      3245  3.6  0.3  4440 1760 pts/3    S+   10:37   0:05 ./test

with an output of:
called PQconnectdb: 0x804a008
called PQexec: 0x80dcbe0
calling PQclear: 0x80dcbe0
calling PQfinish: 0x804a008
...
called PQconnectdb: 0x804a008
called PQexec: 0x80dcea0
calling PQclear: 0x80dcea0
calling PQfinish: 0x804a008
...
called PQconnectdb: 0x804a008
called PQexec: 0x80dd620
calling PQclear: 0x80dd620
calling PQfinish: 0x804a008
...

and valgrind complaining about lost blocks:
==3290== 35224 bytes in 1258 blocks are definitely lost in loss record 8 of 8
==3290==    at 0x1B90459D: malloc (vg_replace_malloc.c:130)
==3290==    by 0x1BC38E3B: (within /lib/tls/i686/cmov/libresolv-2.3.2.so)
==3290==    by 0x1BC37B92: __libc_res_nquery (in /lib/tls/i686/cmov/libresolv-2.3.2.so)
==3290==    by 0x1BC38289: (within /lib/tls/i686/cmov/libresolv-2.3.2.so)
==3290==    by 0x1BC37E8F: __libc_res_nsearch (in /lib/tls/i686/cmov/libresolv-2.3.2.so)
==3290==    by 0x1BDA307D: ???
==3290==    by 0x1B9EFA65: (within /lib/tls/i686/cmov/libc-2.3.2.so)
==3290==    by 0x1B9F0673: getaddrinfo (in /lib/tls/i686/cmov/libc-2.3.2.so)
==3290==    by 0x1B925701: getaddrinfo_all (in /usr/lib/libpq.so.3.1)
==3290==    by 0x1B916F0B: (within /usr/lib/libpq.so.3.1)
==3290==    by 0x1B9164B9: PQconnectStart (in /usr/lib/libpq.so.3.1)
==3290==    by 0x1B916441: PQconnectdb (in /usr/lib/libpq.so.3.1)


With the IP in the host field:
fubar:~# while true; do ps aux|grep -v grep|grep test; sleep 30; done
root      3312  1.4  0.2  3872 1092 pts/3    S+   10:42   0:00 ./test
root      3312  1.6  0.2  3872 1092 pts/3    S+   10:42   0:00 ./test
root      3312  1.9  0.2  3872 1092 pts/3    S+   10:42   0:01 ./test
root      3312  2.0  0.2  3872 1092 pts/3    S+   10:42   0:01 ./test
root      3312  2.0  0.2  3872 1092 pts/3    S+   10:42   0:02 ./test

output:
called PQconnectdb: 0x804a008
called PQexec: 0x80525b8
calling PQclear: 0x80525b8
calling PQfinish: 0x804a008
...
called PQconnectdb: 0x804a008
called PQexec: 0x80525b8
calling PQclear: 0x80525b8
calling PQfinish: 0x804a008
...
called PQconnectdb: 0x804a008
called PQexec: 0x80525b8
calling PQclear: 0x80525b8
calling PQfinish: 0x804a008
...

and no leaking output from valgrind.

Best regards,
 Karsten Desler

Attachment

pgsql-bugs by date:

Previous
From: "Greg Steffensen"
Date:
Subject: BUG #1748: Unique contraints cannot be added to long text fields
Next
From: Tom Lane
Date:
Subject: Re: BUG #1736: endless loop in PQconnectdb