changeset 555:b7434a34a1f4

- FIX: Memory-leak with the "filters" local variable - Renamed some local variable names
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 03 Jan 2022 20:20:32 +0100
parents 36d7aa000435
children 3d5ef056134c
files configmix/_speedups.c
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/_speedups.c	Mon Jan 03 00:11:41 2022 +0100
+++ b/configmix/_speedups.c	Mon Jan 03 20:20:32 2022 +0100
@@ -213,18 +213,18 @@
 {
     Py_UCS4 c;
     unsigned char buf[6];
-    Py_ssize_t buf_bytes;
+    Py_ssize_t bytes_written;
     PyObject *u;
 
     if (_hex2ucs4(s, end, &c) != 0)
         return NULL;
 
     /* Replace the combination PyUniode_New/PyUnicode_WriteChar */
-    buf_bytes = _convert_ucs4_to_utf8(c, s, end+1, buf, &(buf[6]), 1);
-    if (buf_bytes < 0) {
+    bytes_written = _convert_ucs4_to_utf8(c, s, end+1, buf, &(buf[6]), 1);
+    if (bytes_written < 0) {
         return NULL;
     }
-    u = PyUnicode_FromStringAndSize((const char *)buf, buf_bytes);
+    u = PyUnicode_FromStringAndSize((const char *)buf, bytes_written);
     if (u == NULL) {
         return NULL;
     }
@@ -833,11 +833,11 @@
         Py_DECREF(varname);
         Py_INCREF(tmp2);
         varname = tmp2;
-        tmp2 = PyTuple_GetItem(tmp, 1);   /* borrowed -- cannot fail */
-        Py_INCREF(tmp2);
-        filters = tmp2;
+        tmp2 = NULL;
+        filters = PyTuple_GetItem(tmp, 1);   /* borrowed -- cannot fail */
+        Py_INCREF(filters);
         Py_DECREF(tmp);
-        tmp = tmp2 = NULL;
+        tmp = NULL;
 
         tmp = PyObject_CallMethod(
             config, "_getvar_s_with_cache_info", "O", varname);
@@ -898,6 +898,8 @@
         varvalue = tmp;
         tmp = NULL;
 
+        Py_DECREF(filters); filters = NULL;
+
         /*
          * Dont apply and type conversions to the variable value if
          * the whole `s` is just one expansion
@@ -938,7 +940,6 @@
 success:
     Py_DECREF(parts);
     Py_DECREF(res_parts);
-    Py_XDECREF(filters);
 
     if (use_cache) {
         PyDict_SetItem(cache, s, res);