From e6e5cdf0d28c68c180759946b504457b0fb7c040 Mon Sep 17 00:00:00 2001 From: cgohlke Date: Fri, 25 Jan 2019 13:31:14 -0800 Subject: [PATCH 1/2] Fix unhandled C++ exception The C++ new operator will throw an C++ exception when the memory allocation fails. --- src/_tkagg.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index 89f1d6f696b5..2d8bfc271dfe 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -115,8 +115,10 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int destheight = (int)(y2 - y1); deststride = 4 * destwidth; - destbuffer = new agg::int8u[deststride * destheight]; - if (destbuffer == NULL) { + try { + destbuffer = new agg::int8u[deststride * destheight]; + } + catch (...) { TCL_APPEND_RESULT(interp, "could not allocate memory", (char *)NULL); return TCL_ERROR; } From 41af6fc98cb1efe80d34c9ad41f721645a423f2a Mon Sep 17 00:00:00 2001 From: Christoph Gohlke Date: Sat, 2 Feb 2019 10:55:04 -0800 Subject: [PATCH 2/2] Catch only std::bad_alloc --- src/_tkagg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index 2d8bfc271dfe..47862838bbda 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -118,7 +118,7 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int try { destbuffer = new agg::int8u[deststride * destheight]; } - catch (...) { + catch (std::bad_alloc) { TCL_APPEND_RESULT(interp, "could not allocate memory", (char *)NULL); return TCL_ERROR; }