On Wed, Jun 15, 2011 at 5:34 AM, Peter Eisentraut <pete...@gmx.net> wrote: > With gcc 4.6, I get this warning: > > dblink.c: In function ‘dblink_send_query’: > dblink.c:620:7: warning: variable ‘freeconn’ set but not used > [-Wunused-but-set-variable] > > I don't know much about the internals of dblink, but judging from the > surrounding code, I guess that this fix is necessary: > > diff --git i/contrib/dblink/dblink.c w/contrib/dblink/dblink.c > index 19b98fb..e014c1a 100644 > --- i/contrib/dblink/dblink.c > +++ w/contrib/dblink/dblink.c > @@ -634,6 +634,10 @@ dblink_send_query(PG_FUNCTION_ARGS) > if (retval != 1) > elog(NOTICE, "%s", PQerrorMessage(conn)); > > + /* if needed, close the connection to the database and cleanup */ > + if (freeconn) > + PQfinish(conn); > + > PG_RETURN_INT32(retval); > } > > Otherwise the connection might not get freed. Could someone verify > that?
ISTM that the root problem is that dblink_send_query calls DBLINK_GET_CONN though it doesn't accept the connection string as an argument. Since the first argument in dblink_send_query must be the connection name, dblink_send_query should call DBLINK_GET_NAMED_CONN instead. The variable 'freeconn' is used only when DBLINK_GET_CONN is called. So, if dblink_send_query uses DBLINK_GET_NAMED_CONN instead, the variable 'freeconn' is no longer necessary. The similar problem exists in dblink_get_result and dblink_record_internal. Attached patch fixes those problems. Regards, -- Fujii Masao NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
*** a/contrib/dblink/dblink.c --- b/contrib/dblink/dblink.c *************** *** 613,628 **** Datum dblink_send_query(PG_FUNCTION_ARGS) { PGconn *conn = NULL; - char *connstr = NULL; char *sql = NULL; remoteConn *rconn = NULL; - char *msg; - bool freeconn = false; int retval; if (PG_NARGS() == 2) { ! DBLINK_GET_CONN; sql = text_to_cstring(PG_GETARG_TEXT_PP(1)); } else --- 613,625 ---- dblink_send_query(PG_FUNCTION_ARGS) { PGconn *conn = NULL; char *sql = NULL; remoteConn *rconn = NULL; int retval; if (PG_NARGS() == 2) { ! DBLINK_GET_NAMED_CONN; sql = text_to_cstring(PG_GETARG_TEXT_PP(1)); } else *************** *** 711,723 **** dblink_record_internal(FunctionCallInfo fcinfo, bool is_async) if (PG_NARGS() == 2) { /* text,bool */ ! DBLINK_GET_CONN; fail = PG_GETARG_BOOL(1); } else if (PG_NARGS() == 1) { /* text */ ! DBLINK_GET_CONN; } else /* shouldn't happen */ --- 708,720 ---- if (PG_NARGS() == 2) { /* text,bool */ ! DBLINK_GET_NAMED_CONN; fail = PG_GETARG_BOOL(1); } else if (PG_NARGS() == 1) { /* text */ ! DBLINK_GET_NAMED_CONN; } else /* shouldn't happen */
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers