From b17fe185aa1ec15af13e7b1d9666ca8885bf6d85 Mon Sep 17 00:00:00 2001 From: Ajay Kamdar Date: Mon, 24 Jul 2023 08:29:03 -0700 Subject: [PATCH] Should not return freed pointer --- src/fuzzy.pyx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/fuzzy.pyx b/src/fuzzy.pyx index c09fe7f..87bc116 100644 --- a/src/fuzzy.pyx +++ b/src/fuzzy.pyx @@ -188,10 +188,15 @@ def nysiis(s): cdef class Soundex: cdef int size cdef char *map + cdef char* pout def __init__(self, size): self.size = size self.map = "01230120022455012623010202" + self.pout = malloc(self.size + 1) + + def __del__(self): + free(self.pout) def __call__(self, s): cdef char *cs @@ -203,7 +208,7 @@ cdef class Soundex: written = 0 - out = malloc(self.size + 1) + out = self.pout cs = s ls = strlen(cs) for i from 0<= i < ls: @@ -224,10 +229,7 @@ cdef class Soundex: out[i] = 48 out[self.size] = 0 - pout = out - free(out) - - return pout + return out cdef extern from "double_metaphone.h":