From edbb3784070284cffc6ad6024b4245a757bef085 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 4 Dec 2017 10:04:57 +0100 Subject: [PATCH] Add valgrind target to check for memory leaks Signed-off-by: Christian Heimes --- CHANGES | 1 + Doc/contributing.rst | 4 +++- Doc/spelling_wordlist.txt | 1 + Makefile | 16 ++++++++++++++- Misc/python-ldap.supp | 41 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 Misc/python-ldap.supp diff --git a/CHANGES b/CHANGES index df35179..f75659d 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Infrastructure: * Remove distclean.sh in favor of make clean * Use `package`, `depends`, `install_requires` in setup.py * Add make target for scan-build (static analysis using clang) +* Add make target and suppression file for Valgrind (memory checker) Modules/ * Remove unused LDAPberval helper functions diff --git a/Doc/contributing.rst b/Doc/contributing.rst index aa6097d..114541f 100644 --- a/Doc/contributing.rst +++ b/Doc/contributing.rst @@ -168,13 +168,15 @@ We use several specialized tools for debugging and maintenance. Make targets ------------ -``make lcov-open`` +``make lcov lcov-open`` Generate and view test coverage for C code. Requires ``make`` and ``lcov``. ``make scan-build`` Run static analysis. Requires ``clang``. +``make valgrind`` + Run Valgrind to check for memory leaks. Requires ``valgrind`` Reference leak tests -------------------- diff --git a/Doc/spelling_wordlist.txt b/Doc/spelling_wordlist.txt index 95a5df6..70c07e6 100644 --- a/Doc/spelling_wordlist.txt +++ b/Doc/spelling_wordlist.txt @@ -150,5 +150,6 @@ userApplications userPassword usr uuids +Valgrind whitespace workflow diff --git a/Makefile b/Makefile index 1ee3eda..f648d95 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ LCOV_REPORT=build/lcov_report LCOV_REPORT_OPTIONS=--show-details -no-branch-coverage \ --title "python-ldap LCOV report" SCAN_REPORT=build/scan_report +PYTHON_SUPP=/usr/share/doc/python3-devel/valgrind-python.supp .NOTPARALLEL: @@ -18,6 +19,9 @@ clean: -delete find . -depth -name __pycache__ -exec rm -rf {} \; +build: + mkdir -p build + # LCOV report (measuring test coverage for C code) .PHONY: lcov-clean lcov-coverage lcov-report lcov-open lcov lcov-clean: @@ -27,7 +31,7 @@ lcov-clean: lcov-coverage: WITH_GCOV=1 tox -e py27,py36 -$(LCOV_INFO): +$(LCOV_INFO): build lcov --capture --directory build --output-file $(LCOV_INFO) $(LCOV_REPORT): $(LCOV_INFO) @@ -49,3 +53,13 @@ scan-build: scan-build -o $(SCAN_REPORT) --html-title="python-ldap scan report" \ -analyze-headers --view \ $(PYTHON) setup.py clean --all build + +# valgrind memory checker +.PHONY: valgrind +valgrind: build + valgrind --leak-check=full \ + --suppressions=$(PYTHON_SUPP) \ + --suppressions=Misc/python-ldap.supp \ + --gen-suppressions=all \ + --log-file=build/valgrind.log \ + $(PYTHON) setup.py test diff --git a/Misc/python-ldap.supp b/Misc/python-ldap.supp new file mode 100644 index 0000000..de70446 --- /dev/null +++ b/Misc/python-ldap.supp @@ -0,0 +1,41 @@ +# Valgrind suppression file for Python 3.6. + +{ + Ignore libldap memory leak, https://github.com/python-ldap/python-ldap/issues/82 + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:ber_memalloc_x + fun:ber_flatten + fun:ldap_cancel + fun:l_ldap_cancel + ... +} + +{ + Known leak in SASL interaction, https://github.com/python-ldap/python-ldap/issues/81 + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:strdup + fun:interaction + fun:py_ldap_sasl_interaction + fun:ldap_int_sasl_bind + fun:ldap_sasl_interactive_bind + fun:ldap_sasl_interactive_bind_s + fun:l_ldap_sasl_interactive_bind_s + ... +} + +{ + Ignore possible leaks in exception initialization + Memcheck:Leak + match-leak-kinds: possible + fun:malloc + fun:PyObject_Malloc + ... + fun:PyErr_NewException + fun:LDAPinit_constants + fun:init_ldap_module + ... +}