plug memory leak in x11.c

try to obey the Xt toolkit protocol when closing widgets and application
This commit is contained in:
rlar 2012-08-19 18:58:31 +02:00
parent cb42989204
commit 6c01089be1
3 changed files with 26 additions and 2 deletions

View File

@ -419,7 +419,8 @@ int DevSwitch(char *devname)
} else {
dispdev->Close();
if (dispdev)
dispdev->Close();
dispdev = lastdev;
lastdev = NULL;

View File

@ -10,9 +10,11 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
#include "ftehelp.h"
#include "ngspice/hlpdefs.h"
#include "misccoms.h"
#include "postcoms.h"
#include "circuits.h"
#include "variable.h"
#include "plotting/graf.h"
#include "display.h"
#ifdef HAVE_GNUREADLINE
#include <readline/readline.h>
@ -51,6 +53,12 @@ com_quit(wordlist *wl)
/* start to clean up the mess */
{
wordlist *t = wl_cons(copy("all"), NULL);
com_destroy(t);
wl_free(t);
}
#ifdef EXPERIMENTAL_CODE
/* Destroy CKT when quit. Add by Gong Ding, gdiso@ustc.edu */
if (!ft_nutmeg) {
@ -61,6 +69,9 @@ com_quit(wordlist *wl)
}
#endif
DevSwitch(NULL);
DevSwitch(NULL);
/* then go away */
byemesg();
exit(exitcode);

View File

@ -507,7 +507,16 @@ X11_NewViewport(GRAPH *graph)
int
X11_Close(void)
{
XCloseDisplay(display);
// don't, this has never been mapped, there is no window ...
// XtUnmapWidget(toplevel);
XtDestroyWidget(toplevel);
XtAppContext app = XtDisplayToApplicationContext(display);
XtDestroyApplicationContext(app);
// don't, XtDestroyApplicationContext(app) seems to have done that
// XCloseDisplay(display);
return 0;
}
@ -909,7 +918,10 @@ RemoveWindow(GRAPH *graph)
/* Iplots are done asynchronously */
DEVDEP(graph).isopen = 0;
/* MW. Not sure but DestroyGraph might free() to much - try Xt...() first */
XtUnmapWidget(DEVDEP(graph).shell);
XtDestroyWidget(DEVDEP(graph).shell);
XFreeFont(display, DEVDEP(graph).font);
XFreeGC(display, DEVDEP(graph).gc);
}
if (graph == currentgraph)