--- generic/tclIOCmd.c.orig	Tue Sep 21 00:20:40 1999
+++ generic/tclIOCmd.c	Thu Jul 19 02:03:42 2001
@@ -228,8 +228,6 @@
         return TCL_ERROR;
     }
 
-    resultPtr = Tcl_GetObjResult(interp);
-    linePtr = resultPtr;
     if (objc == 3) {
 	/*
 	 * Variable gets line, interp get bytecount.
@@ -237,11 +235,14 @@
 
 	linePtr = Tcl_NewObj();
     }
+    else {
+	linePtr = Tcl_GetObjResult(interp);
+    }
 
     lineLen = Tcl_GetsObj(chan, linePtr);
     if (lineLen < 0) {
         if (!Tcl_Eof(chan) && !Tcl_InputBlocked(chan)) {
-	    if (linePtr != resultPtr) {
+	    if (objc == 3) {
 		Tcl_DecrRefCount(linePtr);
 	    }
 	    Tcl_ResetResult(interp);
@@ -257,6 +258,7 @@
 	    Tcl_DecrRefCount(linePtr);
             return TCL_ERROR;
         }
+	resultPtr = Tcl_GetObjResult(interp);
 	Tcl_SetIntObj(resultPtr, lineLen);
         return TCL_OK;
     }
