From: Andrew R. <an...@co...> - 2004-01-23 11:23:28
|
On Wed, Jan 21, 2004 at 01:17:11PM -0800, Alan Irwin wrote: > This new bug for CVS HEAD is clearly generated because of Andrew Ross's > memory management fixups, but I suspect what is going on is that other parts > of the code base (in this case the pltcl application) are being sloppy about > initializing the library and this has now become revealed because of > Andrew's fixups. > > It's your call, Rafael, about whether these segfaults are a sufficiently > rare case so we won't worry about it for release or whether we should wait > until post-release to deal with all the memory management fixups together. > > Anyhow, here is what I noticed. In the installed tcl examples, you can > execute single tcl examples with special scripts x01, x02,...., and those > scripts are now producing segfaults with CVS HEAD which were not produced > before. > > If I follow the x01 script and execute by hand > > valgrind pltcl -dev psc -o test.ps > > and then type in the commands in the pltcl environment: > > source x01.tcl > plinit > x01 > plend > exit > > If I remove plend from the above sequence, then there is no valgrind error > or segfault. (Note the only reason I haven't seen segfaults from CVS HEAD > for the test_tcl.sh script invoked by plplot-test.sh is that I did not use > plend in that script to terminate the plotting.) Alan, The problem here is two fold. Firstly pltcl is trying to be clever and is overriding exit so that it calls plend. plend is therefore being executed twice. The second problem is that plend doesn't actually check that the library has been initialised before freeing the memory. I've got a (1-line) patch to plend in plcore.c to check that the library is actually initialized before freeing up the memory. SF is not yet letting me in to the CVS even though I've been added to the plplot team so I can't submit it myself. If someone else wants to do it I propose just adding if (lib_initialized == 0) return; to the top of plend(). I've tested and this fixes the tcl problem. Andrew |