with self.assertWarns(DeprecationWarning):
self.assertIsNone(getargs_Z_hash(None))
+ def test_gh_99240_clear_args(self):
+ from _testcapi import gh_99240_clear_args
+ self.assertRaises(TypeError, gh_99240_clear_args, 'a', '\0b')
+
class Object_TestCase(unittest.TestCase):
def test_S(self):
Py_RETURN_NONE;
}
+static PyObject *
+gh_99240_clear_args(PyObject *self, PyObject *args)
+{
+ char *a = NULL;
+ char *b = NULL;
+
+ if (!PyArg_ParseTuple(args, "eses", "idna", &a, "idna", &b)) {
+ if (a || b) {
+ PyErr_Clear();
+ PyErr_SetString(PyExc_AssertionError, "Arguments are not cleared.");
+ }
+ return NULL;
+ }
+ PyMem_Free(a);
+ PyMem_Free(b);
+ Py_RETURN_NONE;
+}
+
static PyMethodDef test_methods[] = {
{"get_args", get_args, METH_VARARGS},
{"get_kwargs", _PyCFunction_CAST(get_kwargs), METH_VARARGS|METH_KEYWORDS},
{"test_empty_argparse", test_empty_argparse, METH_NOARGS},
{"test_k_code", test_k_code, METH_NOARGS},
{"test_s_code", test_s_code, METH_NOARGS},
+ {"gh_99240_clear_args", gh_99240_clear_args, METH_VARARGS},
{NULL},
};
static int
cleanup_ptr(PyObject *self, void *ptr)
{
- if (ptr) {
- PyMem_Free(ptr);
- }
+ void **pptr = (void **)ptr;
+ PyMem_Free(*pptr);
+ *pptr = NULL;
return 0;
}
PyErr_NoMemory();
RETURN_ERR_OCCURRED;
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(buffer, freelist, cleanup_ptr)) {
Py_DECREF(s);
return converterr(
"(cleanup problem)",
PyErr_NoMemory();
RETURN_ERR_OCCURRED;
}
- if (addcleanup(*buffer, freelist, cleanup_ptr)) {
+ if (addcleanup(buffer, freelist, cleanup_ptr)) {
Py_DECREF(s);
return converterr("(cleanup problem)",
arg, msgbuf, bufsize);