Fix connection leak in dblink when dblink_connect() or dblink_connect_u()
authorItagaki Takahiro <itagaki.takahiro@gmail.com>
Wed, 9 Jun 2010 01:00:13 +0000 (01:00 +0000)
committerItagaki Takahiro <itagaki.takahiro@gmail.com>
Wed, 9 Jun 2010 01:00:13 +0000 (01:00 +0000)
end with "duplicate connection name" errors.

Backported to release 7.4.

contrib/dblink/dblink.c

index 16f502008183ea5adc0af817e6000bb5de5ff565..f67128e7519d70b408f9024e0b5781775f80590c 100644 (file)
@@ -2151,9 +2151,14 @@ createNewConnection(const char *name, remoteConn * rconn)
                                                                                           HASH_ENTER, &found);
 
        if (found)
+       {
+               PQfinish(rconn->conn);
+               pfree(rconn);
+
                ereport(ERROR,
                                (errcode(ERRCODE_DUPLICATE_OBJECT),
                                 errmsg("duplicate connection name")));
+       }
 
        hentry->rconn = rconn;
        strncpy(hentry->name, name, NAMEDATALEN - 1);