X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 1A154D1C9B3 for ; Fri, 8 Aug 2003 08:46:25 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 94900-10 for ; Fri, 8 Aug 2003 05:44:59 -0300 (ADT) Received: from gatefox.foxi.nl (a194-109-246-192.adsl.xs4all.nl [194.109.246.192]) by svr1.postgresql.org (Postfix) with ESMTP id 23727D1C9AB for ; Fri, 8 Aug 2003 05:46:13 -0300 (ADT) Received: from techfox.foxi (techfox.foxi [192.168.0.79]) by gatefox.foxi.nl (8.10.2/8.10.2) with ESMTP id h788kAL05660; Fri, 8 Aug 2003 10:46:11 +0200 From: Frank van Vugt Organization: Foxi Consultants in Technology BV To: Tom Lane Subject: SOLVED: Multi-threaded Qt app segfaults when using libpq with separate connections Date: Fri, 8 Aug 2003 10:46:10 +0200 User-Agent: KMail/1.5.1 Cc: pgsql-interfaces@postgresql.org References: <200308041729.13212.ftm.van.vugt@foxi.nl> <200308050034.20405.ftm.van.vugt@foxi.nl> <13531.1060036862@sss.pgh.pa.us> In-Reply-To: <13531.1060036862@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308081046.10157.ftm.van.vugt@foxi.nl> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/38 X-Sequence-Number: 4392 Hi, I *finally* nailed this thing, turns out NOT to be a PG problem, more like PEBKC. Tom Lane wrote: > I get the impression that something is clobbering memory with abandon. He was write (duh..). What wasn't clear (at least to me) from the Qt-docs is that a name given to a supplementary database connection must be unique, otherwise the new one will replace the old one. Expecting to be able to handle the connections by the pointers an addDatabase() call returned, I had been creating new connections in separate threads whose names weren't always unique. Since 'connection' here implicates a PGconn structure, I had been 'switching' PGconn structures while in use. It seems one can even get away with that for a limited number of threads, but at a certain point newly created result structures (PGresult, PQntubles, PQnfields, etc.) will be allocated space on top of the older structures belonging the replaced connections, which is obviously the point where things get very messy.... I've asked the Trolls (Qt) to emphasize this potential problem in their docs. Thanks to Tom Lane (PostgreSQL) and Harald Fernengel (TrollTech) for their pointers ;) Best, Frank van Vugt