From 076c604de8e61e65a95607253455dc926fe0f6d9 Mon Sep 17 00:00:00 2001 From: versat Date: Wed, 18 Sep 2019 15:09:13 +0200 Subject: [PATCH] python.cfg: Improve Python C API configuration Add configurations for types, macros, alloc/dealloc and functions. --- cfg/python.cfg | 149 ++++++++++++++++++++++++++++++++++++++++++++++ test/cfg/python.c | 27 +++++++++ 2 files changed, 176 insertions(+) diff --git a/cfg/python.cfg b/cfg/python.cfg index 2901b41aa..76cdf91f6 100644 --- a/cfg/python.cfg +++ b/cfg/python.cfg @@ -1,6 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PyMem_Malloc + PyMem_Calloc + PyMem_Realloc + PyMem_Free + + + PyMem_RawMalloc + PyMem_RawCalloc + PyMem_RawRealloc + PyMem_RawFree + + + PyObject_Malloc + PyObject_Calloc + PyObject_Realloc + PyObject_Free + + @@ -20,6 +78,22 @@ + + + true + + + + + + + + true + + + + + false @@ -337,6 +411,81 @@ + + + + + false + + + + 1: + + + + 0: + + + + + + false + + + + + + + + + false + + + + + 0: + + + + + + + + false + + + + + + 0: + + + + + false + + + + + + + + false + + + + + + + false + + + + + + + + diff --git a/test/cfg/python.c b/test/cfg/python.c index 86ed76d82..011e140b5 100644 --- a/test/cfg/python.c +++ b/test/cfg/python.c @@ -9,6 +9,7 @@ #define PY_SSIZE_T_CLEAN #include // should be the first include +#include void validCode(PyObject * pPyObjArg) { @@ -23,6 +24,11 @@ void validCode(PyObject * pPyObjArg) Py_CLEAR(pPyObjArg); Py_CLEAR(pPyObjNULL); (void)PyErr_NewException("text", NULL, NULL); + + char * pBuf1 = PyMem_Malloc(5); + PyMem_Free(pBuf1); + int * pIntBuf1 = PyMem_New(int, 10); + PyMem_Free(pIntBuf1); } void nullPointer() @@ -32,3 +38,24 @@ void nullPointer() // cppcheck-suppress nullPointer Py_DECREF(NULL); } + +void PyMem_Malloc_memleak() +{ + char * pBuf1 = PyMem_Malloc(1); + printf("%p", pBuf1); + // cppcheck-suppress memleak +} + +void PyMem_Malloc_mismatchAllocDealloc() +{ + char * pBuf1 = PyMem_Malloc(10); + // cppcheck-suppress mismatchAllocDealloc + free(pBuf1); +} + +void PyMem_New_memleak() +{ + char * pBuf1 = PyMem_New(char, 5); + printf("%p", pBuf1); + // cppcheck-suppress memleak +}