Ensure usage of __attribute__(cleanup) never frees un-initialized memory

Use macros that take an initializer parameter to, thereby ensuring the
variable to be cleaned up is always initialized.
This commit is contained in:
Kovid Goyal
2023-08-07 11:52:52 +05:30
parent 9af4d5e0fc
commit 6c7a8f8fa9
19 changed files with 75 additions and 77 deletions

View File

@@ -26,7 +26,7 @@ serialize_string_tuple(PyObject *src) {
const char *pysrc = PyUnicode_AsUTF8(PyTuple_GET_ITEM(src, i));
if (!pysrc) {
PyErr_Clear();
DECREF_AFTER_FUNCTION PyObject *u8 = PyUnicode_AsEncodedString(PyTuple_GET_ITEM(src, i), "UTF-8", "ignore");
RAII_PyObject(u8, PyUnicode_AsEncodedString(PyTuple_GET_ITEM(src, i), "UTF-8", "ignore"));
if (!u8) { PyErr_Print(); fatal("couldn't parse command line"); }
ans[i] = calloc(PyBytes_GET_SIZE(u8) + 1, sizeof(char));
if (ans[i] == NULL) fatal("Out of memory");