Re: XForms: Memory Leak with Statically Inited Menus

Ivan Powis (pczip@chemistry.nottingham.ac.uk)
Mon, 12 Jan 1998 16:56:04 GMT

To subscribers of the xforms list from Ivan Powis <pczip@chemistry.nottingham.ac.uk> :

>
> To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :
>

> > fl_hide_form(ob->form);
> > fl_free_form(ob->form);
> > free(ob->form->fdui);
>
> This is a nit but this is probably bad practice since fl_free_form(),
> by necessity, does a free() of the form's data structures. Thus, in
> the subsequent free() of `fdui', you are dereferencing a no longer
> valid pointer. I'd flip the order:
>

Agreed, but this crept in because my demo was a quick hack. In my usual
applications I don't use ob->form->fdui directly in the free() but a
previously copied (and still valid) pointer to it. Either way this
isn't the root cause of my problem.

>
> I think the problem is assuming that fl_free_form() destroys the
> popup as well. Popups, being basically independent Windows sort of

Sure, its also my interpretation that the pop-ups aren't being freed
when the form is killed. However, I think the issue here is a question
of philosophy about the objectives of the library. Given that popups
are not _explicitly_ used here, I believe that it is not unreasonable
to expect that they would be managed without explicit intervention by
me. Remember what I did was to use the menu specification tab facility
in fdesign to automatically create an initialised menu, being supposedly
marginally more convenient than programming with fl_set_menu() calls
etc to accomplish the same thing. But in this latter situation I
wouldn't need to get into bookeeping the 'behind the scenes'
popups. It seems to me dangerous to find oneself tempted into using
the fl_set_menu_entries() as a 'convenience' if this implicitly requires
later having to get involved in internal workings of the menu object.

>
> I suppose that XForms could easily keep track of what Popup belongs to
> what Window and scan the list of Popups whenever fl_free_form() is
> executed.
>

Of course, I imagine it does this when fl_set_menu() has been used?
So to express my point another way, should I be required to take
different steps to free up a form, depending on which one of two
alternative, but broadly equivalent 'high-level' routes, I've taken in
creating it?

Ivan

--
-------------------------------------------------------------------------+
    ___  ___/   _  __ /  Ivan Powis                TEL: +44-115-951-3467 |
        /         /   /  Department of Chemistry   FAX: +44-115-951-3562 |
       /         /  _/   University of Nottingham                        |
      /         ___/     Nottingham NG7 2RD                              |
     /         /         UK                                              |
    /         /                      pczip@chem.nott.ac.uk               | 
_______/  ____/                      http://www.chem.nott.ac.uk/IP.html  |
-------------------------------------------------------------------------+

_________________________________________________ To unsubscribe, send the message "unsubscribe" to xforms-request@bob.usuf2.usuhs.mil or see http://bob.usuf2.usuhs.mil/mailserv/xforms.html Xforms Home Page: http://bloch.phys.uwm.edu/xforms List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/