plug dblink resource leak
authorJoe Conway <[email protected]>
Sat, 12 Sep 2009 23:20:52 +0000 (23:20 +0000)
committerJoe Conway <[email protected]>
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 83b334c4f60f3bc04ab768236acc5355aa8eb72f..72fdf56a711e0935aee9435f15e3bfcfdaef3e33 100644 (file)
@@ -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);
                }