GNOME Bugzilla – Bug 690512
GIMP plugins uses GEGL through GIMP's running PID, hence buffer swapped on disk, created from plugins, are not removed at plugin closure
Last modified: 2013-02-07 10:23:51 UTC
When you run gegl_end(), GEGL would clean all swap files from disk, which have been created by the running PID. For this purpose, swap files are prefixed with the PID. This allows to clean any swap created by a program when you quit it (right now none of the disk space is freed during running time, only at exit. I have created bug 690509 with a patch for this other issue). Problem with GIMP architecture if that if a plugin works with image, layers, etc., it actually communicate with GIMP and GIMP does the work. So it means that, even with my fix in bug 690509, if ever a plugin is badly written and does not delete created images/layers/buffers before exiting (even if calling gegl_exit()), or if it crashes, the swap files won't be deleted because they are considered to belong to GIMP PID and not the plugin PID. Hence the disk will fill up with more and more swap files until GIMP exits, and GIMP does not even know about them. It also means that the GEGL buffers, images, etc. may also be kept into memory and never freed (hence memory leak too). How to test: 1/ run a plugin which creates/duplicates an image or layers (basically most export plugins do this for instance, they often first duplicate the image then merge the layers, etc.). 2/ check in the swap directory after the plugin ended that all swap files created and swapped to disk are tagged with GIMP PID (and not the plugin's one), and that they are still there. Obviously this is a complicated problem and there is no easy solution. Couldn't there be some some way to tell GEGL to work on behalf another PID than itself? This way: 1/ when the plug-in ends with gegl_exit(), this time it will delete its own swap files. 2/ there could be some "garbage collector" system, which allows GIMP to delete swap files from a plug-in which crashed (for instance), or simply which forgot to close gegl_end() at the end.
I think it might be better if GIMP keeps track of buffers created by plug-ins, and reap them at plug-in end if they haven't been reaped (with an appropriate warning printed to stderr when it happens.) Changing product to GIMP.
I don't see what you mean, what "buffers" are there that are not some drawable's buffers? They are all owned by the GIMP process. I don't see a problem here, the same thing happens when you simply duplicate the image in the UI and then close it. Also, didn't you just push some fix to GEGL that actually removes the swap files when the buffer is finalized?
Yes I did push a patch which removes swap when the buffer is finalized. This is a related, but different issue. The problem is that the buffers that a plugin creates through libgimp may never be finalized (even with a gegl_exit()) because they are not considered to belong to the plugin. If a plugin calls GEGL directly, any created buffer belongs to it, so when it quits with a gegl_exit(), all swap are deleted (and memory is freed with process too, of course). That's ok. But when a plugin calls some libgimp function, which in turns sends a message to GIMP which calls GEGL as a result, any created buffer belongs to the main GIMP process. So even though the plugin runs gegl_exit(), all the swap stays on disk and all the buffers that the plugin initiated through libgimp stay alive as belonging to the main GIMP process, unless they were explicitly finalized at exit. It means that any plugin right now which does not exit with proper cleaning (a created/duplicated GimpImage must be removed by a gimp_image_delete, etc.) leaves unfinished business in GIMP state (buffers never finalized, hence some memory leak, probably some swap files, etc.). So that makes that GIMP will react very badly to badly written plugin, filling both disk space and memory, even after the plugin finished (and even if it did not crash). What proposes Pippin above seems a good idea. GIMP could keep track of all GEGL buffers on behalf of a plugin and finalize them after the plugin ended, if the plugin did not do it.
So this is essentially a duplicate of bug #8141, our oldest open bug? :)
Looks similar indeed. :-) Though I guess bug #8141 was not about GEGL buffers, since it dates from 2001. But the general issue description looks the same indeed.
Let's consider the swap files a side effect of the same bug. All buffers actually do belong to drawables. *** This bug has been marked as a duplicate of bug 8141 ***