From 295b02cdfbc034362af781b66d116e86198e8dd7 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 25 Mar 2024 16:27:09 +0000 Subject: [PATCH] Fix [76646bdf6]: "photo get" command leaks memory --- generic/tkImgPhoto.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index bb9416e53..f45fac517 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -940,7 +940,7 @@ ImgPhotoCmd( */ Tcl_Obj *channels[4]; - int channelCount = 3; + int i, channelCount = 3; index = 3; memset(&options, 0, sizeof(options)); @@ -976,10 +976,9 @@ ImgPhotoCmd( */ pixelPtr = modelPtr->pix32 + (y * modelPtr->width + x) * 4; - channels[0] = Tcl_NewWideIntObj(pixelPtr[0]); - channels[1] = Tcl_NewWideIntObj(pixelPtr[1]); - channels[2] = Tcl_NewWideIntObj(pixelPtr[2]); - channels[3] = Tcl_NewWideIntObj(pixelPtr[3]); + for (i = 0; i < channelCount; i++) { + channels[i] = Tcl_NewWideIntObj(pixelPtr[i]); + } Tcl_SetObjResult(interp, Tcl_NewListObj(channelCount, channels)); return TCL_OK; }