vendor/tramline

changeset 4:b7abc7431525 gracinet-fix-range

Fixed a memory leak
author gracinet
date Tue, 10 Feb 2009 13:55:29 +0000
parents 5265ba1c57bd
children 235dfe5e7ce9
files src/tramline/core.py
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/tramline/core.py
     1.2 +++ b/src/tramline/core.py
     1.3 @@ -330,6 +330,7 @@
     1.4          self.id = id
     1.5          self._upload_files = []
     1.6          self._incoming = []
     1.7 +	self._isize = 0
     1.8          # we use a state pattern where the handle method gets
     1.9          # replaced by the current handle method for this state.
    1.10          self.handle = self.handle_first_boundary
    1.11 @@ -344,9 +345,14 @@
    1.12      def pushInputLine(self, data, out):
    1.13          # collect data
    1.14          self._incoming.append(data)
    1.15 +	self._isize += len(data)
    1.16 +
    1.17          # if we're not at the end of the line, input was broken
    1.18 -        # somewhere. We return to collect more first.
    1.19 -        if data[-1] != '\n':
    1.20 +        # somewhere, unless we are handling file data which might be binary.
    1.21 +	# We return to collect more first (also for file data if too small)
    1.22 +        if data[-1] != '\n' and (
    1.23 +           self.handle != self.handle_file_data or
    1.24 +               self._isize < FILE_CHUNKSIZE/2):
    1.25              return
    1.26          # now use the line in whatever handle method is current
    1.27          if len(self._incoming) == 1:
    1.28 @@ -354,6 +360,7 @@
    1.29          else:
    1.30              line = ''.join(self._incoming)
    1.31          self._incoming = []
    1.32 +        self._isize = 0
    1.33  
    1.34          self.handle(line, out)
    1.35