From 7d27109da91753ce0ed031d0c7c3eb095b0b7fed Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 5 May 2014 17:18:51 +0000 Subject: Segfaulting test (backport of iortrans-5.11). --- tests/iogt.test | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/iogt.test b/tests/iogt.test index d81acd6..abe4246 100644 --- a/tests/iogt.test +++ b/tests/iogt.test @@ -251,7 +251,17 @@ proc id_torture {chan op data} { clear_read {;#ignore} flush/write - flush/read {} - write - + write { + global level + if {$level} { + return + } + incr level + testchannel unstack $chan + testchannel transform $chan \ + -command [namespace code [list id_torture $chan]] + return $data + } read { testchannel unstack $chan testchannel transform $chan \ @@ -665,6 +675,16 @@ test iogt-2.4 {basic I/O, mixed trail} {testchannel} { close $fh set x } {} +test iogt-2.5 {basic I/O, mixed trail} {testchannel} { + set ::level 0 + set fh [open $path(dummyout) w] + torture -attach $fh + puts -nonewline $fh abcdef + flush $fh + testchannel unstack $fh + close $fh + set x +} {} test iogt-3.0 {Tcl_Channel valid after stack/unstack, fevent handling} \ {testchannel unknownFailure} { -- cgit v0.12 From 0fc3bdcc7e6bd2903a1e84017073bf39dff8a3ad Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 6 May 2014 13:56:29 +0000 Subject: Have to manage the lifetime of the self handle in testchannel transform. --- generic/tclIOGT.c | 15 +++++++++++++-- tests/iogt.test | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/generic/tclIOGT.c b/generic/tclIOGT.c index beddf4f..c5372b1 100644 --- a/generic/tclIOGT.c +++ b/generic/tclIOGT.c @@ -298,7 +298,6 @@ TclChannelTransform( } Tcl_DStringFree(&ds); - dataPtr->self = chan; dataPtr->watchMask = 0; dataPtr->mode = mode; dataPtr->timer = NULL; @@ -317,6 +316,7 @@ TclChannelTransform( ReleaseData(dataPtr); return TCL_ERROR; } + Tcl_Preserve(dataPtr->self); /* * At last initialize the transformation at the script level. @@ -437,6 +437,9 @@ ExecuteCallback( break; case TRANSMIT_DOWN: + if (dataPtr->self == NULL) { + break; + } resObj = Tcl_GetObjResult(eval); resBuf = Tcl_GetByteArrayFromObj(resObj, &resLen); Tcl_WriteRaw(Tcl_GetStackedChannel(dataPtr->self), (char *) resBuf, @@ -444,6 +447,9 @@ ExecuteCallback( break; case TRANSMIT_SELF: + if (dataPtr->self == NULL) { + break; + } resObj = Tcl_GetObjResult(eval); resBuf = Tcl_GetByteArrayFromObj(resObj, &resLen); Tcl_WriteRaw(dataPtr->self, (char *) resBuf, resLen); @@ -579,6 +585,8 @@ TransformCloseProc( * General cleanup. */ + Tcl_Release(dataPtr->self); + dataPtr->self = NULL; ReleaseData(dataPtr); return TCL_OK; } @@ -614,7 +622,7 @@ TransformInputProc( * Should assert(dataPtr->mode & TCL_READABLE); */ - if (toRead == 0) { + if (toRead == 0 || dataPtr->self == NULL) { /* * Catch a no-op. */ @@ -1083,6 +1091,9 @@ TransformWatchProc( * unchanged. */ + if (dataPtr->self == NULL) { + return; + } downChan = Tcl_GetStackedChannel(dataPtr->self); Tcl_GetChannelType(downChan)->watchProc( diff --git a/tests/iogt.test b/tests/iogt.test index abe4246..d4291b3 100644 --- a/tests/iogt.test +++ b/tests/iogt.test @@ -683,7 +683,6 @@ test iogt-2.5 {basic I/O, mixed trail} {testchannel} { flush $fh testchannel unstack $fh close $fh - set x } {} test iogt-3.0 {Tcl_Channel valid after stack/unstack, fevent handling} \ -- cgit v0.12