From ad99f496f08e7d050cf298b8ea5aba1579640c25 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 19 Dec 2018 19:33:59 -0500 Subject: [PATCH] Fix memleak in `_korlib.create_bump_LUT()` --- korlib/bumpmap.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/korlib/bumpmap.cpp b/korlib/bumpmap.cpp index 00ca20f..10d2eb0 100644 --- a/korlib/bumpmap.cpp +++ b/korlib/bumpmap.cpp @@ -33,8 +33,9 @@ typedef struct { extern "C" { PyObject* create_bump_LUT(PyObject*, PyObject* args) { - const int kLUTHeight = 16; - const int kLUTWidth = 16; + static const int kLUTHeight = 16; + static const int kLUTWidth = 16; + static const int kBufSz = kLUTWidth * kLUTWidth * sizeof(uint32_t); pyMipmap* pymipmap; if (!PyArg_ParseTuple(args, "O", &pymipmap)) { @@ -54,7 +55,7 @@ PyObject* create_bump_LUT(PyObject*, PyObject* args) { int startH = delH / 2 + 1; int doneH = 0; - uint8_t* data = new uint8_t[texture->getTotalSize()]; + uint8_t data[kBufSz]; uint32_t* pix = (uint32_t*)data; int i; @@ -105,7 +106,7 @@ PyObject* create_bump_LUT(PyObject*, PyObject* args) { } } - texture->setImageData(data, texture->getTotalSize()); + texture->setImageData(data, kBufSz); Py_RETURN_NONE; }