[Gridflow-dev] read PNG memory leak patch (untested!)
Claude Heiland-Allen
claudiusmaximus at goto10.org
Tue Jul 3 06:01:01 EDT 2007
Hi matju, all,
I reported a memory leak on #dataflow; basically after reading 30000+
PNG images, Pd+GridFlow uses 300MB+ ram...
I think I found the solution, it involves explicitly reading the png
info at the end of the file and also explicitly freeing it, as opposed
to pretending there isn't any extra data...
Note: I haven't tested this, having trouble compiling gridflow cvs on
pure:dyne, but I've adapted this patched png.c code in a standalone
program without any memory leaks.
Hope this is useful...
Claude
(~/pd/gridflow/format) # diff -uw png.c.orig png.c
--- png.c.orig 2007-07-03 07:48:16.000000000 +0000
+++ png.c 2007-07-03 07:51:02.000000000 +0000
@@ -34,6 +34,7 @@
P<BitPacking> bit_packing;
png_structp png;
png_infop info;
+ png_infop infoend;
int fd;
FILE *f;
FormatPNG () : bit_packing(0), png(0), f(0) {}
@@ -71,6 +72,10 @@
if (!info) {
png_destroy_read_struct(&png, NULL, NULL); RAISE("!info");
}
+ infoend = png_create_info_struct(png);
+ if (!infoend) {
+ png_destroy_read_struct(&png, NULL, NULL);
RAISE("!infoend");
+ }
if (setjmp(png_jmpbuf(png))) {
png_destroy_read_struct(&png, &info, NULL); RAISE("png
read error");
}
@@ -108,13 +113,13 @@
png_read_image(png, row_pointers);
delete row_pointers;
row_pointers = 0;
- png_read_end(png, 0);
+ png_read_end(png, infoend);
GridOutlet out(this,0,new Dim(height, width, channels),
NumberTypeE_find(rb_ivar_get(rself,SI(@cast))));
out.send(rowbytes*height,image_data);
free(image_data);
- png_destroy_read_struct(&png, &info, NULL);
+ png_destroy_read_struct(&png, &info, &infoend);
return Qnil;
}
zsh: exit 1 diff -uw png.c.orig png.c
More information about the Gridflow-dev
mailing list