From 2b9f4668b69bd78c2ebb56f77626898486ba7c84 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Aug 2012 11:44:40 -0700 Subject: [PATCH] images: gdiplus had a resource leak (file descriptor). change stream>image to dispose of the stream no matter what. --- basis/images/loader/cocoa/cocoa.factor | 2 +- basis/images/loader/gdiplus/gdiplus.factor | 13 ++++++------- basis/images/loader/gtk/gtk.factor | 11 +++++------ basis/images/loader/loader.factor | 11 +++++++---- extra/images/bitmap/bitmap.factor | 2 +- extra/images/gif/gif.factor | 2 +- extra/images/pbm/pbm.factor | 2 +- extra/images/pgm/pgm.factor | 2 +- extra/images/png/png.factor | 2 +- extra/images/ppm/ppm.factor | 2 +- extra/images/tga/tga.factor | 2 +- extra/images/tiff/tiff.factor | 2 +- 12 files changed, 27 insertions(+), 26 deletions(-) diff --git a/basis/images/loader/cocoa/cocoa.factor b/basis/images/loader/cocoa/cocoa.factor index 6680a4f317..b3d05999f9 100644 --- a/basis/images/loader/cocoa/cocoa.factor +++ b/basis/images/loader/cocoa/cocoa.factor @@ -33,5 +33,5 @@ os macosx? [ 0 0 w h image CGContextDrawImage ] make-bitmap-image ; -M: ns-image stream>image +M: ns-image stream>image* drop stream-contents CGImage>image ; diff --git a/basis/images/loader/gdiplus/gdiplus.factor b/basis/images/loader/gdiplus/gdiplus.factor index 3ac0e2accf..5ef2bd05ca 100644 --- a/basis/images/loader/gdiplus/gdiplus.factor +++ b/basis/images/loader/gdiplus/gdiplus.factor @@ -57,10 +57,9 @@ os windows? [ PRIVATE> -M: gdi+-image stream>image - drop [ - start-gdi+ &stop-gdi+ drop - stream>gdi+-bitmap - gdi+-bitmap>data - data>image - ] with-destructors ; +M: gdi+-image stream>image* + drop + start-gdi+ &stop-gdi+ drop + stream>gdi+-bitmap + gdi+-bitmap>data + data>image ; diff --git a/basis/images/loader/gtk/gtk.factor b/basis/images/loader/gtk/gtk.factor index 1cf39e6885..69ec5f8974 100644 --- a/basis/images/loader/gtk/gtk.factor +++ b/basis/images/loader/gtk/gtk.factor @@ -64,9 +64,8 @@ os linux? [ PRIVATE> -M: gtk-image stream>image - drop [ - stream-contents data>GInputStream &g_object_unref - GInputStream>GdkPixbuf &g_object_unref - GdkPixbuf>image - ] with-destructors ; +M: gtk-image stream>image* + drop + stream-contents data>GInputStream &g_object_unref + GInputStream>GdkPixbuf &g_object_unref + GdkPixbuf>image ; diff --git a/basis/images/loader/loader.factor b/basis/images/loader/loader.factor index 7be8300f63..6bd5d54a28 100644 --- a/basis/images/loader/loader.factor +++ b/basis/images/loader/loader.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: ascii assocs byte-arrays io.encodings.binary io.files -io.pathnames io.streams.byte-array kernel namespaces sequences -strings fry ; +USING: ascii assocs byte-arrays destructors fry +io.encodings.binary io.files io.pathnames io.streams.byte-array +kernel namespaces sequences strings ; IN: images.loader ERROR: unknown-image-extension extension ; @@ -24,7 +24,10 @@ PRIVATE> GENERIC# load-image* 1 ( obj class -- image ) -GENERIC: stream>image ( stream class -- image ) +GENERIC: stream>image* ( stream class -- image ) + +: stream>image ( stream class -- image ) + '[ _ &dispose _ stream>image* ] with-destructors ; inline : register-image-class ( extension class -- ) swap types get set-at ; diff --git a/extra/images/bitmap/bitmap.factor b/extra/images/bitmap/bitmap.factor index 01c9ba00a9..f637dca987 100644 --- a/extra/images/bitmap/bitmap.factor +++ b/extra/images/bitmap/bitmap.factor @@ -370,7 +370,7 @@ ERROR: unsupported-bitmap-file magic ; : loading-bitmap>bytes ( loading-bitmap -- byte-array ) uncompress-bitmap bitmap>bytes ; -M: bmp-image stream>image ( stream bmp-image -- bitmap ) +M: bmp-image stream>image* ( stream bmp-image -- bitmap ) drop load-bitmap [ image new ] dip { diff --git a/extra/images/gif/gif.factor b/extra/images/gif/gif.factor index 92ed3cd995..25776bffdd 100644 --- a/extra/images/gif/gif.factor +++ b/extra/images/gif/gif.factor @@ -248,5 +248,5 @@ ERROR: loading-gif-error gif-image ; : ensure-loaded ( gif-image -- gif-image ) dup loading?>> [ loading-gif-error ] when ; -M: gif-image stream>image ( path gif-image -- image ) +M: gif-image stream>image* ( path gif-image -- image ) drop load-gif ensure-loaded gif>image ; diff --git a/extra/images/pbm/pbm.factor b/extra/images/pbm/pbm.factor index a6e7edb9e2..35e14cc9a6 100644 --- a/extra/images/pbm/pbm.factor +++ b/extra/images/pbm/pbm.factor @@ -72,7 +72,7 @@ SINGLETON: pbm-image ubyte-components >>component-type ; PRIVATE> -M: pbm-image stream>image +M: pbm-image stream>image* drop [ [ read-pbm ] throw-on-eof ] with-input-stream ; M: pbm-image image>stream diff --git a/extra/images/pgm/pgm.factor b/extra/images/pgm/pgm.factor index 4457c89135..d8e1033c90 100644 --- a/extra/images/pgm/pgm.factor +++ b/extra/images/pgm/pgm.factor @@ -49,7 +49,7 @@ SINGLETON: pgm-image data >>bitmap wide [ ushort-components ] [ ubyte-components ] if >>component-type ; -M: pgm-image stream>image +M: pgm-image stream>image* drop [ [ read-pgm ] throw-on-eof ] with-input-stream ; M: pgm-image image>stream diff --git a/extra/images/png/png.factor b/extra/images/png/png.factor index f98eeedd77..ac60820878 100644 --- a/extra/images/png/png.factor +++ b/extra/images/png/png.factor @@ -357,5 +357,5 @@ ERROR: invalid-color-type/bit-depth loading-png ; ] throw-on-eof ] with-input-stream ; -M: png-image stream>image +M: png-image stream>image* drop load-png loading-png>image ; diff --git a/extra/images/ppm/ppm.factor b/extra/images/ppm/ppm.factor index 454a4b34f5..865f377fbc 100755 --- a/extra/images/ppm/ppm.factor +++ b/extra/images/ppm/ppm.factor @@ -46,7 +46,7 @@ SINGLETON: ppm-image data >>bitmap ubyte-components >>component-type ; -M: ppm-image stream>image +M: ppm-image stream>image* drop [ [ read-ppm ] throw-on-eof ] with-input-stream ; M: ppm-image image>stream diff --git a/extra/images/tga/tga.factor b/extra/images/tga/tga.factor index efdcbc537c..f2fd8e8660 100644 --- a/extra/images/tga/tga.factor +++ b/extra/images/tga/tga.factor @@ -253,7 +253,7 @@ ERROR: bad-tga-unsupported ; image-data >>bitmap ubyte-components >>component-type ; -M: tga-image stream>image +M: tga-image stream>image* drop [ [ read-tga ] throw-on-eof ] with-input-stream ; M: tga-image image>stream diff --git a/extra/images/tiff/tiff.factor b/extra/images/tiff/tiff.factor index c8a3f76353..2a6e184a3b 100755 --- a/extra/images/tiff/tiff.factor +++ b/extra/images/tiff/tiff.factor @@ -560,7 +560,7 @@ ERROR: unknown-component-order ifd ; [ process-tif-ifds ] with-tiff-endianness ; ! tiff files can store several images -- we just take the first for now -M: tiff-image stream>image ( stream tiff-image -- image ) +M: tiff-image stream>image* ( stream tiff-image -- image ) drop [ [ load-tiff tiff>image ] throw-on-eof ] with-input-stream ; { "tif" "tiff" } [ tiff-image register-image-class ] each