Skip to content

Commit

Permalink
Add valgrind target to check for memory leaks
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes committed Dec 5, 2017
1 parent ed0f6ed commit edbb378
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------
Expand Down
1 change: 1 addition & 0 deletions Doc/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ userApplications
userPassword
usr
uuids
Valgrind
whitespace
workflow
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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
41 changes: 41 additions & 0 deletions Misc/python-ldap.supp
Original file line number Diff line number Diff line change
@@ -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
...
}

0 comments on commit edbb378

Please sign in to comment.