From a2471e236906503a2079fe9806303ff31e832cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 16 Jun 2019 15:23:08 +0200 Subject: tests: add the reproducer from #51 The example relies on implementation details, but I don't see why it wouldn't work everywhere. Let's pull it in, and if it breaks somewhere, we can remove it. --- systemd/test/test_daemon.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/systemd/test/test_daemon.py b/systemd/test/test_daemon.py index 1ddb55e..9f4db7d 100644 --- a/systemd/test/test_daemon.py +++ b/systemd/test/test_daemon.py @@ -302,3 +302,16 @@ def test_notify_with_socket(tmpdir): assert notify('FDSTORE=1', fds=[1, 2]) assert notify('FDSTORE=1', pid=os.getpid()) assert notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) + +def test_daemon_notify_memleak(): + # https://github.com/systemd/python-systemd/pull/51 + fd = 1 + fds = [fd] + ref_cnt = sys.getrefcount(fd) + + try: + notify('', True, 0, fds) + except ConnectionRefusedError: + pass + + assert sys.getrefcount(fd) <= ref_cnt, 'leak' -- cgit v1.2.1