From 6bd362f5ebd7fdb3764939db9122976accf28b9f Mon Sep 17 00:00:00 2001 From: Camille Scott Date: Thu, 6 Jun 2019 13:46:15 -0700 Subject: [PATCH] Fix memory leak in `MinHash.intersection`. (#687) The intersection function uses the `new` operator to construct a `KmerMinHash` or `KmerMinAbundance`. Although this is Cython, `new` still heap-allocates the object, and it is *not* marked for garbage collection, because it isn't a PyObject. This commit calls delete (`del`) on the allocated object to prevent it from being leaked. --- sourmash/_minhash.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sourmash/_minhash.pyx b/sourmash/_minhash.pyx index 565221866..af9471c30 100644 --- a/sourmash/_minhash.pyx +++ b/sourmash/_minhash.pyx @@ -324,7 +324,10 @@ cdef class MinHash(object): common.intersection_update(other.get_mins()) common.intersection_update(combined_mh.mins) - return common, max(combined_mh.size(), 1) + size = max(combined_mh.size(), 1) + del combined_mh + + return common, size def compare(self, MinHash other): common, size = self.intersection(other)