From: Reuben Thomas Date: Thu, 25 Jan 2018 14:55:35 +0000 (+0000) Subject: Recode.pyx: fix space leaks in Request and Task X-Git-Tag: v3.7~55 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b9f9ccaa43d0bc68bb4b5654bb25ac05cc50a09;p=recode Recode.pyx: fix space leaks in Request and Task Incidentally use a more modern way to import the FILE type --- diff --git a/tests/Recode.pyx b/tests/Recode.pyx index 8cf0fb7..f929c34 100644 --- a/tests/Recode.pyx +++ b/tests/Recode.pyx @@ -19,10 +19,8 @@ # 02111-1307, USA. from libcpp cimport bool - -cdef extern from "stdio.h": - struct FILE: - pass +from libc.stdlib cimport free +from libc.stdio cimport FILE cdef extern from "common.h": @@ -650,7 +648,11 @@ cdef class Request: result = recode_buffer_to_buffer(self.request, input, input_len, &output, &output_len, &output_allocated) if result is False or output is NULL: raise error - return output[:output_len] + try: + py_string = output[:output_len] + finally: + free (output) + return py_string # Unexposed APIs: @@ -683,6 +685,7 @@ cdef class Task: self.task = recode_new_task(request.request) def __dealloc__(self): + free (self.task.output.buffer) recode_delete_task(self.task) def set_byte_order_mark(self, flag):