]> granicus.if.org Git - recode/commitdiff
Recode.pyx: fix space leaks in Request and Task
authorReuben Thomas <rrt@sc3d.org>
Thu, 25 Jan 2018 14:55:35 +0000 (14:55 +0000)
committerReuben Thomas <rrt@sc3d.org>
Fri, 26 Jan 2018 11:51:21 +0000 (11:51 +0000)
Incidentally use a more modern way to import the FILE type

tests/Recode.pyx

index 8cf0fb7856556ba27172e9aa3c6e9ecd787ed494..f929c3433412fe9664f0a1371dedcccd7b7f44fa 100644 (file)
 # 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):