comparison configmix/_speedups.c @ 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
comparison
equal deleted inserted replaced
554:36d7aa000435 555:b7434a34a1f4
211 PyObject * 211 PyObject *
212 _hex2string(PyObject *s, Py_ssize_t end) 212 _hex2string(PyObject *s, Py_ssize_t end)
213 { 213 {
214 Py_UCS4 c; 214 Py_UCS4 c;
215 unsigned char buf[6]; 215 unsigned char buf[6];
216 Py_ssize_t buf_bytes; 216 Py_ssize_t bytes_written;
217 PyObject *u; 217 PyObject *u;
218 218
219 if (_hex2ucs4(s, end, &c) != 0) 219 if (_hex2ucs4(s, end, &c) != 0)
220 return NULL; 220 return NULL;
221 221
222 /* Replace the combination PyUniode_New/PyUnicode_WriteChar */ 222 /* Replace the combination PyUniode_New/PyUnicode_WriteChar */
223 buf_bytes = _convert_ucs4_to_utf8(c, s, end+1, buf, &(buf[6]), 1); 223 bytes_written = _convert_ucs4_to_utf8(c, s, end+1, buf, &(buf[6]), 1);
224 if (buf_bytes < 0) { 224 if (bytes_written < 0) {
225 return NULL; 225 return NULL;
226 } 226 }
227 u = PyUnicode_FromStringAndSize((const char *)buf, buf_bytes); 227 u = PyUnicode_FromStringAndSize((const char *)buf, bytes_written);
228 if (u == NULL) { 228 if (u == NULL) {
229 return NULL; 229 return NULL;
230 } 230 }
231 return u; 231 return u;
232 } 232 }
831 /* Unpack the result tuple */ 831 /* Unpack the result tuple */
832 tmp2 = PyTuple_GetItem(tmp, 0); /* borrowed -- cannot fail */ 832 tmp2 = PyTuple_GetItem(tmp, 0); /* borrowed -- cannot fail */
833 Py_DECREF(varname); 833 Py_DECREF(varname);
834 Py_INCREF(tmp2); 834 Py_INCREF(tmp2);
835 varname = tmp2; 835 varname = tmp2;
836 tmp2 = PyTuple_GetItem(tmp, 1); /* borrowed -- cannot fail */ 836 tmp2 = NULL;
837 Py_INCREF(tmp2); 837 filters = PyTuple_GetItem(tmp, 1); /* borrowed -- cannot fail */
838 filters = tmp2; 838 Py_INCREF(filters);
839 Py_DECREF(tmp); 839 Py_DECREF(tmp);
840 tmp = tmp2 = NULL; 840 tmp = NULL;
841 841
842 tmp = PyObject_CallMethod( 842 tmp = PyObject_CallMethod(
843 config, "_getvar_s_with_cache_info", "O", varname); 843 config, "_getvar_s_with_cache_info", "O", varname);
844 if (tmp == NULL) { 844 if (tmp == NULL) {
845 if (PyErr_ExceptionMatches(PyExc_KeyError)) { 845 if (PyErr_ExceptionMatches(PyExc_KeyError)) {
896 } 896 }
897 Py_DECREF(varvalue); 897 Py_DECREF(varvalue);
898 varvalue = tmp; 898 varvalue = tmp;
899 tmp = NULL; 899 tmp = NULL;
900 900
901 Py_DECREF(filters); filters = NULL;
902
901 /* 903 /*
902 * Dont apply and type conversions to the variable value if 904 * Dont apply and type conversions to the variable value if
903 * the whole `s` is just one expansion 905 * the whole `s` is just one expansion
904 */ 906 */
905 if (first_part_is_empty && (i == 1) && (pb_len == s_len - 2) && (idx == pb_len - 2)) { 907 if (first_part_is_empty && (i == 1) && (pb_len == s_len - 2) && (idx == pb_len - 2)) {
936 } 938 }
937 939
938 success: 940 success:
939 Py_DECREF(parts); 941 Py_DECREF(parts);
940 Py_DECREF(res_parts); 942 Py_DECREF(res_parts);
941 Py_XDECREF(filters);
942 943
943 if (use_cache) { 944 if (use_cache) {
944 PyDict_SetItem(cache, s, res); 945 PyDict_SetItem(cache, s, res);
945 PyErr_Clear(); /* clear any possible cache-related error */ 946 PyErr_Clear(); /* clear any possible cache-related error */
946 } 947 }