Subject: Repair linked list management in Tcl_DeleteCloseHandler(). CloseCallback struct is used only locally. Remove from tclIO.h.

From: dgp <[email-masked]>
Date: Mon, 25 Feb 2013 18:05:22 +0000

---
 generic/tclIO.c | 14 ++++++++++++++
 generic/tclIO.h | 16 ++++------------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/generic/tclIO.c b/generic/tclIO.c
index eace472..ed08112 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -70,6 +70,18 @@ typedef struct ThreadSpecificData {
 static Tcl_ThreadDataKey dataKey;
 
 /*
+ * Structure to record a close callback. One such record exists for
+ * each close callback registered for a channel.
+ */
+
+typedef struct CloseCallback {
+    Tcl_CloseProc *proc;		/* The procedure to call. */
+    ClientData clientData;		/* Arbitrary one-word data to pass
+					 * to the callback. */
+    struct CloseCallback *nextPtr;	/* For chaining close callbacks. */
+} CloseCallback;
+
+/*
  * Static functions in this file:
  */
 
@@ -504,6 +516,8 @@ Tcl_DeleteCloseHandler(chan, proc, clientData)
         if ((cbPtr->proc == proc) && (cbPtr->clientData == clientData)) {
             if (cbPrevPtr == (CloseCallback *) NULL) {
                 statePtr->closeCbPtr = cbPtr->nextPtr;
+	    } else {
+		cbPrevPtr->nextPtr = cbPtr->nextPtr;
             }
             ckfree((char *) cbPtr);
             break;
diff --git a/generic/tclIO.h b/generic/tclIO.h
index e9f6151..2c7978a 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -85,17 +85,8 @@ typedef struct ChannelBuffer {
 
 #define CHANNELBUFFER_DEFAULT_SIZE	(1024 * 4)
 
-/*
- * Structure to record a close callback. One such record exists for
- * each close callback registered for a channel.
- */
-
-typedef struct CloseCallback {
-    Tcl_CloseProc *proc;		/* The procedure to call. */
-    ClientData clientData;		/* Arbitrary one-word data to pass
-					 * to the callback. */
-    struct CloseCallback *nextPtr;	/* For chaining close callbacks. */
-} CloseCallback;
+/* Foward declaration */
+struct CloseCallback;
 
 /*
  * The following structure describes the information saved from a call to
@@ -197,7 +188,8 @@ typedef struct ChannelState {
     int refCount;		/* How many interpreters hold references to
 				 * this IO channel? */
 
-    CloseCallback *closeCbPtr;	/* Callbacks registered to be called when the
+    struct CloseCallback *closeCbPtr;
+				/* Callbacks registered to be called when the
 				 * channel is closed. */
     char *outputStage;		/* Temporary staging buffer used when
 				 * translating EOL before converting from
-- 
cgit v0.12