The patch attached should  do the trick. Could someone with 
valgrind test that it does indeed cure a memory leak?

Just open and close the About LyX dialog a few times and then 
exit.

Regards,
Angus
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.549
diff -u -p -r1.549 ChangeLog
--- src/frontends/xforms/ChangeLog	26 Sep 2002 08:57:43 -0000	1.549
+++ src/frontends/xforms/ChangeLog	26 Sep 2002 11:34:58 -0000
@@ -1,3 +1,13 @@
+2002-09-26  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* FormBase.h (prepare_to_show): new method.
+	(icon_pixmap_, icon_mask_): new member variables.
+
+	* FormBase.C (prepare_to_show): move initialisation code invoked the
+	first time show is called here.
+	(d-tor): destroy the icon pixmap, if it exists.
+	(show): ensure that the icon Pixmap is generated only once.
+
 2002-09-25  Angus Leeming  <[EMAIL PROTECTED]>
 
 	* Dialogs2.C:
Index: src/frontends/xforms/FormBase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormBase.C,v
retrieving revision 1.59
diff -u -p -r1.59 FormBase.C
--- src/frontends/xforms/FormBase.C	9 Sep 2002 09:49:47 -0000	1.59
+++ src/frontends/xforms/FormBase.C	26 Sep 2002 11:34:58 -0000
@@ -40,12 +40,17 @@ static int C_PrehandlerCB(FL_OBJECT *, i
 
 FormBase::FormBase(string const & t, bool allowResize)
 	: ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
-	  title_(t), tooltips_(new Tooltips())
+	  title_(t), icon_pixmap_(0), icon_mask_(0),
+	  tooltips_(new Tooltips())
+	  
 {}
 
 
 FormBase::~FormBase()
 {
+	if (icon_pixmap_)
+		XFreePixmap(fl_get_display(), icon_pixmap_);
+
 	delete tooltips_;
 }
 
@@ -70,30 +75,56 @@ xformsBC & FormBase::bc()
 }
 
 
-void FormBase::show()
+void FormBase::prepare_to_show()
 {
-	if (!form()) {
-		build();
+	double const scale = scale_to_fit_tabs(form());
+	if (scale > 1.001)
+		scale_form(form(), scale);
+
+	bc().refresh();
+
+	// work around dumb xforms sizing bug
+	minw_ = form()->w;
+	minh_ = form()->h;
+
+	fl_set_form_atclose(form(), C_WMHideCB, 0);
+
+	if (!getController().IconifyWithMain()) {
+		// set title for minimized form
+		fl_winicontitle(form()->window, title_.c_str());
+
+		//  assign an icon to the form
+		string const iconname = LibFileSearch("images", "lyx", "xpm");
+		if (!iconname.empty()) {
+			unsigned int w, h;
+			icon_pixmap_ = fl_read_pixmapfile(fl_root,
+							  iconname.c_str(),
+							  &w,
+							  &h,
+							  &icon_mask_,
+							  0, 0, 0);
+			fl_set_form_icon(form(), icon_pixmap_, icon_mask_);
+		}
 	}
+}
 
-	// use minw_ to flag whether the dialog has ever been shown
-	// (Needed now that build() is/should be called from the controller)
-	if (minw_ == 0) {
-		double const scale = scale_to_fit_tabs(form());
-		if (scale > 1.001)
-			scale_form(form(), scale);
-
-		bc().refresh();
-
-		// work around dumb xforms sizing bug
-		minw_ = form()->w;
-		minh_ = form()->h;
 
-		fl_set_form_atclose(form(), C_WMHideCB, 0);
+void FormBase::show()
+{
+	// build() is/should be called from the controller, so form() should
+	// always exist.
+	lyx::Assert(form());
+
+	// we use minw_ to flag whether the dialog has ever been shown.
+	// In turn, prepare_to_show() initialises various bits 'n' pieces
+	// (including minw_).
+	if (minw_ == 0) {
+		prepare_to_show();
 	}
 
+	// make sure the form is up to date.
 	fl_freeze_form(form());
-	update();  // make sure its up-to-date
+	update();
 	fl_unfreeze_form(form());
 
 	if (form()->visible) {
@@ -115,35 +146,17 @@ void FormBase::show()
 			fl_set_form_maxsize(form(), minw_, minh_);
 
 		string const maximize_title = "LyX: " + title_;
-		int const iconify_policy = getController().IconifyWithMain() ?
-						FL_TRANSIENT : 0;
+		int const iconify_policy =
+			getController().IconifyWithMain() ? FL_TRANSIENT : 0;
 
 		fl_show_form(form(),
 			     FL_PLACE_MOUSE | FL_FREE_SIZE,
 			     iconify_policy,
 			     maximize_title.c_str());
-
-		if (iconify_policy == 0) {
-			// set title for minimized form
-			string const minimize_title = title_;
-			fl_winicontitle(form()->window, minimize_title.c_str());
-
-			//  assign an icon to form
-			string const iconname = LibFileSearch("images", "lyx", "xpm");
-			if (!iconname.empty()) {
-				unsigned int w, h;
-				Pixmap icon_mask;
-				Pixmap const icon_p = fl_read_pixmapfile(fl_root,
-							iconname.c_str(),
-							&w,
-							&h,
-							&icon_mask,
-							0, 0, 0); // this leaks
-                		fl_set_form_icon(form(), icon_p, icon_mask);
-        		}
-		}
 	}
 
+	// For some strange reason known only to xforms, the tooltips can only
+	// be set on a form that is already visible...
 	tooltips().set();
 }
 
Index: src/frontends/xforms/FormBase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormBase.h,v
retrieving revision 1.47
diff -u -p -r1.47 FormBase.h
--- src/frontends/xforms/FormBase.h	5 Sep 2002 15:14:21 -0000	1.47
+++ src/frontends/xforms/FormBase.h	26 Sep 2002 11:34:58 -0000
@@ -25,6 +25,7 @@
 #include "FeedbackController.h"
 
 #include <boost/scoped_ptr.hpp>
+#include <X11/Xlib.h> // for Pixmap
 
 #include "forms_fwd.h"
 
@@ -79,14 +80,23 @@ private:
 	 */
 	virtual void redraw();
 
+	/** Called on the first show() request, initialising various bits and
+	 *  pieces.
+	 */
+	void prepare_to_show();
+
 	/// The dialog's minimum allowable dimensions.
 	int minw_;
 	///
 	int minh_;
 	/// Can the dialog be resized after it has been created?
 	bool allow_resize_;
-	/// dialog title, displayed by WM.
+	/// dialog title, displayed by the window manager.
 	string title_;
+	/// Passed to the window manager to give a pretty little symbol ;-)
+	Pixmap icon_pixmap_;
+	///
+	Pixmap icon_mask_;
 	///
 	Tooltips * tooltips_;
 };

Reply via email to