plug dblink resource leak
authorJoe Conway
Sat, 12 Sep 2009 23:20:52 +0000 (23:20 +0000)
committerJoe Conway
Sat, 12 Sep 2009 23:20:52 +0000 (23:20 +0000)
dblink generates orphaned connections when called with a connection string,
fail_on_error = true, and an ERROR occurs. Discovery and patch by
Tatsuhito Kasahara. Introduced in 8.4.

contrib/dblink/dblink.c

index ccf8cb2a87d2f0222c4116a0660786691b64073d..61585644f92de1a96e0b6328618622d7411cf745 100644 (file)
@@ -8,7 +8,7 @@
  * Darko Prenosil 
  * Shridhar Daithankar 
  *
- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.83 2009/08/05 16:11:07 joe Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.84 2009/09/12 23:20:52 joe Exp $
  * Copyright (c) 2001-2009, PostgreSQL Global Development Group
  * ALL RIGHTS RESERVED;
  *
@@ -855,9 +855,9 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
            (PQresultStatus(res) != PGRES_COMMAND_OK &&
             PQresultStatus(res) != PGRES_TUPLES_OK))
        {
-           dblink_res_error(conname, res, "could not execute query", fail);
            if (freeconn)
                PQfinish(conn);
+           dblink_res_error(conname, res, "could not execute query", fail);
            MemoryContextSwitchTo(oldcontext);
            SRF_RETURN_DONE(funcctx);
        }