Commit a0d26594 authored by Julien Muchembled's avatar Julien Muchembled

Fix possible resource leak with ImageMagick conversion

parent 10e16f2c
...@@ -26,26 +26,16 @@ class ImageMagickTransforms: ...@@ -26,26 +26,16 @@ class ImageMagickTransforms:
if depth: if depth:
parameter_list.extend(['-depth', '%s' % depth, '-type', 'Palette']) parameter_list.extend(['-depth', '%s' % depth, '-type', 'Palette'])
parameter_list.append('%s:-' % self.format) parameter_list.append('%s:-' % self.format)
process = subprocess.Popen(parameter_list, with subprocess.Popen(parameter_list,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True) close_fds=True) as p:
imgin, imgout, err = process.stdin, process.stdout, process.stderr # XXX: The only portable way is to pass what stdin.write can accept,
# which is a string for PIPE.
image, err = p.communicate(str(orig))
def writeData(stream, data): data.setData(image)
if isinstance(data, str):
stream.write(data)
else:
# Use PData structure to prevent
# consuming too much memory
while data is not None:
stream.write(data.data)
data = data.next
writeData(imgin, orig)
imgin.close()
data.setData(imgout.read())
return data return data
def register(): def register():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment