From: Andrew R. <an...@co...> - 2004-01-16 11:38:08
|
On Fri, Jan 16, 2004 at 08:41:34AM +0000, Andrew Ross wrote: > > There are undoubtedly some memory issues here. The fact that my code > used to work with static drivers suggests that some things may not > be freed by plend. I've already been using valgrind to track bugs in > my own code so I'm quite happy to look at plplot a bit more closely > as well. I'll report back to the list. To follow up my earlier message, I have now used valgrind to take a closer look at the cleanup code. The attached patch has two main roles. Firstly it will free up the dispatch tables in plend(). The second change is to add #ifndef ENABLE_DYNDRIVERS ... #endif about the lines in plD_dispatch_init_XXXXX which assign pdt->pl_MenuStr and pdt->pl_DevName. If this is a dynamic driver then we have already assigned these strings in plcore.c using the database. We absolutely don't want to use a static string in the dynamic driver to initialise it with since that string will disappear once the driver is unloaded and we are left with no valid driver name or menu item. Oh and overwriting the string will also leak the previously allocated memory for the names. I can now run the C examples under valgrind using the ps driver for instance and all the memory is correctly freed up at the end of the program. I also have a test program which does a plend() then recalls plinit() and plend() with all memory properly freed. I've tested with both dynamic and static drivers under Linux - both work. I realise this patch is somewhat larger than my previous one and touches on the drivers too, but I think it is worth it to clean up our memory handling with dynamic drivers (and to a lesser extent with static drivers since there is still memory associated with the dispatch tables in that case). Any comments? Andrew P.S. the patch is against cvs20040104 but I guess not that much has changed on these bits of the code in between. |