diff options
author | das <das> | 2007-09-17 12:07:30 (GMT) |
---|---|---|
committer | das <das> | 2007-09-17 12:07:30 (GMT) |
commit | 3ad66d99fd717405fb14ba64c0c8560bee0dc477 (patch) | |
tree | 2999793a19d9b0b200f79aa7039bd8efeb13e67e | |
parent | a7dee15a2f5e2bfc9ddc2d1bac7db2b82425aa3d (diff) | |
download | tcl-3ad66d99fd717405fb14ba64c0c8560bee0dc477.zip tcl-3ad66d99fd717405fb14ba64c0c8560bee0dc477.tar.gz tcl-3ad66d99fd717405fb14ba64c0c8560bee0dc477.tar.bz2 |
(CopyData): avoid leaking msg and errObj (if interp == NULL)
-rw-r--r-- | generic/tclIO.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index 145d27a..79b8fa1 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIO.c,v 1.123 2007/09/06 18:13:19 dgp Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.124 2007/09/17 12:07:30 das Exp $ */ #include "tclInt.h" @@ -8208,13 +8208,13 @@ CopyData( * Check for unreported background errors. */ - Tcl_GetChannelError (inChan, &msg); + Tcl_GetChannelError(inChan, &msg); if ((inStatePtr->unreportedError != 0) || (msg != NULL)) { Tcl_SetErrno(inStatePtr->unreportedError); inStatePtr->unreportedError = 0; goto readError; } - Tcl_GetChannelError (outChan, &msg); + Tcl_GetChannelError(outChan, &msg); if ((outStatePtr->unreportedError != 0) || (msg != NULL)) { Tcl_SetErrno(outStatePtr->unreportedError); outStatePtr->unreportedError = 0; @@ -8241,13 +8241,19 @@ CopyData( if (size < 0) { readError: - TclNewObj(errObj); - Tcl_AppendStringsToObj(errObj, "error reading \"", - Tcl_GetChannelName(inChan), "\": ", NULL); + if (interp) { + TclNewObj(errObj); + Tcl_AppendStringsToObj(errObj, "error reading \"", + Tcl_GetChannelName(inChan), "\": ", NULL); + if (msg != NULL) { + Tcl_AppendObjToObj(errObj, msg); + } else { + Tcl_AppendStringsToObj(errObj, Tcl_PosixError(interp), + NULL); + } + } if (msg != NULL) { - Tcl_AppendObjToObj(errObj,msg); - } else { - Tcl_AppendStringsToObj(errObj, Tcl_PosixError(interp), NULL); + Tcl_DecrRefCount(msg); } break; } else if (underflow) { @@ -8305,13 +8311,19 @@ CopyData( if (sizeb < 0) { writeError: - TclNewObj(errObj); - Tcl_AppendStringsToObj(errObj, "error writing \"", - Tcl_GetChannelName(outChan), "\": ", NULL); + if (interp) { + TclNewObj(errObj); + Tcl_AppendStringsToObj(errObj, "error writing \"", + Tcl_GetChannelName(outChan), "\": ", NULL); + if (msg != NULL) { + Tcl_AppendObjToObj(errObj, msg); + } else { + Tcl_AppendStringsToObj(errObj, Tcl_PosixError(interp), + NULL); + } + } if (msg != NULL) { - Tcl_AppendObjToObj(errObj,msg); - } else { - Tcl_AppendStringsToObj(errObj, Tcl_PosixError(interp), NULL); + Tcl_DecrRefCount(msg); } break; } |