1313 * Portions Copyright (c) 1994, Regents of the University of California
1414 *
1515 * IDENTIFICATION
16- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.33 2002/09/0221:51:47 tgl Exp $
16+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.34 2002/09/0223:41:17 tgl Exp $
1717 *
1818 *-------------------------------------------------------------------------
1919 */
@@ -144,6 +144,7 @@ static void
144144PgWatchProc (ClientData instanceData ,int mask )
145145{
146146}
147+
147148static int
148149PgGetHandleProc (ClientData instanceData ,int direction ,
149150ClientData * handlePtr )
@@ -193,7 +194,7 @@ PgSetConnectionId(Tcl_Interp *interp, PGconn *conn)
193194
194195#if TCL_MAJOR_VERSION >=8
195196connid -> notifier_channel = Tcl_MakeTcpClientChannel ((ClientData )PQsocket (conn ));
196- Tcl_RegisterChannel (interp ,connid -> notifier_channel );
197+ Tcl_RegisterChannel (NULL ,connid -> notifier_channel );
197198#else
198199connid -> notifier_socket = -1 ;
199200#endif
@@ -227,6 +228,8 @@ PgGetConnectionId(Tcl_Interp *interp, char *id, Pg_ConnectionId ** connid_p)
227228{
228229Tcl_ResetResult (interp );
229230Tcl_AppendResult (interp ,id ," is not a valid postgresql connection" ,0 );
231+ if (connid_p )
232+ * connid_p = NULL ;
230233return (PGconn * )NULL ;
231234}
232235
@@ -285,6 +288,25 @@ PgDelConnectionId(DRIVER_DEL_PROTO)
285288PQfinish (connid -> conn );
286289connid -> conn = NULL ;
287290
291+ /*
292+ * Kill the notifier channel, too. We must not do this until after
293+ * we've closed the libpq connection, because Tcl will try to close
294+ * the socket itself!
295+ *
296+ * XXX Unfortunately, while this works fine if we are closing due to
297+ * explicit pg_disconnect, Tcl versions through 8.3.3 dump core if we
298+ * try to do it during interpreter shutdown. Not clear why, or if
299+ * there is a workaround. For now, accept leakage of the (fairly
300+ * small) amount of memory taken for the channel state representation.
301+ * Note we are not leaking a socket, since libpq closed that already.
302+ */
303+ #ifdef NOT_USED
304+ #if TCL_MAJOR_VERSION >=8
305+ if (connid -> notifier_channel != NULL )
306+ Tcl_UnregisterChannel (NULL ,connid -> notifier_channel );
307+ #endif
308+ #endif
309+
288310/*
289311 * We must use Tcl_EventuallyFree because we don't want the connid
290312 * struct to vanish instantly if Pg_Notify_EventProc is active for it.
@@ -782,8 +804,10 @@ PgStartNotifyEventSource(Pg_ConnectionId * connid)
782804if (pqsock >=0 )
783805{
784806#if TCL_MAJOR_VERSION >=8
785- Tcl_CreateChannelHandler (connid -> notifier_channel ,TCL_READABLE ,
786- Pg_Notify_FileHandler , (ClientData )connid );
807+ Tcl_CreateChannelHandler (connid -> notifier_channel ,
808+ TCL_READABLE ,
809+ Pg_Notify_FileHandler ,
810+ (ClientData )connid );
787811#else
788812/* In Tcl 7.5 and 7.6, we need to gin up a Tcl_File. */
789813Tcl_File tclfile = Tcl_GetFile ((ClientData )pqsock ,TCL_UNIX_FD );
@@ -805,7 +829,8 @@ PgStopNotifyEventSource(Pg_ConnectionId * connid, bool allevents)
805829{
806830#if TCL_MAJOR_VERSION >=8
807831Tcl_DeleteChannelHandler (connid -> notifier_channel ,
808- Pg_Notify_FileHandler , (ClientData )connid );
832+ Pg_Notify_FileHandler ,
833+ (ClientData )connid );
809834#else
810835/* In Tcl 7.5 and 7.6, we need to gin up a Tcl_File. */
811836Tcl_File tclfile = Tcl_GetFile ((ClientData )connid -> notifier_socket ,