From 3ad66d99fd717405fb14ba64c0c8560bee0dc477 Mon Sep 17 00:00:00 2001 From: das Date: Mon, 17 Sep 2007 12:07:30 +0000 Subject: (CopyData): avoid leaking msg and errObj (if interp == NULL) --- generic/tclIO.c | 42 +++++++++++++++++++++++++++--------------- 1 file 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; } -- cgit v0.12