|
From: | jon |
Subject: | Re: [XForms] Bug? |
Date: | Mon, 05 Jan 2015 11:07:31 +0000 |
On Mon, 2015-01-05 at 10:45 +0100, Jens Thoms Toerring wrote: > Hi Jon, > > I just had a bit of a look at the flimage code > and run a few tests. As far as I can see all files > get closed again, so I don't think it's related to > running out of file handles (at least I could open > more than 10000 images and nothing bad happened). > But there's something else I noticed: > > > image=flimage_load("/tmp/cam1m.jpg"); > > if (image) > > { > > flimage_display( image, FL_ObjWin( fd_hc_legacycams->camview1 ) ); > > flimage_free(image); > > flimage_close(image); > > Here you're doing something forbidden: flimage_free() does > already closes the file and also releases all memory for > the structure pointed to by 'image'. Thus after calling > flimage_free() you're not allowed to use that pointer > anymore, also not for flimage_close() since it now points > to memory you don't "own" (and may have become reused for > something else. > > If your intention was to close the file but still be able > to use the image (in memory) call flimage_close() - this > only closes file handles. Call flimage_free() only when > you're done with the image in memory. If you don't call > flimage_close() flimage_free() will close the files for > you automatically, so flimage_close() is actually only > needed for cases where you load a lot of images that you > want to keep in memory while avoiding to run out of file > descriptors. Otherwise calling it is redundant. As always thanks for great advice :-) The code started with just flimage_free(), I added the flimage_close() later in attempt to make it behave. With the help of your ulimit suggestion I think I have found the issue :-) I have two processes running, one reading jpegs from a camera server and the xforms code displaying it. Every so often the reader process grabs a bad image. I managed to catch it at a point when /tmp/cam8m.jpg is broken. If I now run this code with a ulimit -n 10 it fails very quickly, about 8 seconds in. Maybe the corrupt image causes the image code to leave a file open. This project is just for fun so no silly NDA issues. I have written a number of quick hacks to test things, I will then write some proper code in style of well known TV scifi series using the touch screens :-) Thanks, Jon Attached should be enough to duplicate the problem.
email.tar.gz
Description: application/compressed-tar
cam1m.jpg
Description: JPEG image
cam2m.jpg
Description: JPEG image
cam3m.jpg
Description: JPEG image
cam4m.jpg
Description: JPEG image
cam5m.jpg
Description: JPEG image
cam6m.jpg
Description: JPEG image
cam7m.jpg
Description: JPEG image
cam8m.jpg
Description: JPEG image
cam1l.jpg
Description: JPEG image
[Prev in Thread] | Current Thread | [Next in Thread] |