Dominique Pelle wrote:

> On Sun, Jun 8, 2008 at 2:25 PM, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
> 
> > Dominique Pelle wrote:
> >
> >> On Sat, Jun 7, 2008 at 8:44 AM, Dominique Pelle wrote:
> >>
> >> > Attached:
> >> > - crash-os_unix.c.patch
> >> > - leak-os_unix.c.patch
> >>
> >> I built the gui-motif, gui-athena and gui-gtk2 on Linux x86 and the crash 
> >> in
> >> os_unix.c only happens with gui-motif (I'm using LessTif).
> >>
> >> So instead of doing #if 0 as in my previous patch, it should be better to
> >> do #ifndef FEAT_GUI_MOTIF.
> >>
> >> gui-athena shows errors with -DEXITFREE just a few lines below though:
> >>
> >> ==15738== Invalid read of size 4
> >> ==15738==    at 0x42CDEE7: XCloseDisplay (in /usr/lib/libX11.so.6.2.0)
> >> ==15738==    by 0x8140419: mch_free_mem (os_unix.c:2900)
> >> ==15738==    by 0x810A969: free_all_mem (misc2.c:1125)
> >> ==15738==    by 0x8140573: mch_exit (os_unix.c:3012)
> >> ==15738==    by 0x80DE4C8: getout (main.c:1342)
> >> ==15738==    by 0x80A56C3: ex_quit_all (ex_docmd.c:6281)
> >> ==15738==    by 0x809F8CB: do_one_cmd (ex_docmd.c:2623)
> >> ==15738==    by 0x809D18C: do_cmdline (ex_docmd.c:1099)
> >> ==15738==    by 0x812030E: nv_colon (normal.c:5179)
> >> ==15738==    by 0x8119B88: normal_cmd (normal.c:1152)
> >> ==15738==    by 0x80DE20A: main_loop (main.c:1181)
> >> ==15738==    by 0x80DDD5A: main (main.c:940)
> >> ==15738==  Address 0x44020cc is 148 bytes inside a block of size 1,340 
> >> free'd
> >> ==15738==    at 0x402265C: free (vg_replace_malloc.c:323)
> >> ==15738==    by 0x42E0F3E: _XFreeDisplayStructure (in 
> >> /usr/lib/libX11.so.6.2.0)
> >> ==15738==    by 0x42CDFC5: XCloseDisplay (in /usr/lib/libX11.so.6.2.0)
> >> ==15738==    by 0x424EC49: (within /usr/lib/libXt.so.6.0.0)
> >> ==15738==    by 0x424EE36: XtCloseDisplay (in /usr/lib/libXt.so.6.0.0)
> >> ==15738==    by 0x424EE70: (within /usr/lib/libXt.so.6.0.0)
> >> ==15738==    by 0x424F164: XtDestroyApplicationContext (in
> >> /usr/lib/libXt.so.6.0.0)
> >> ==15738==    by 0x81403F4: mch_free_mem (os_unix.c:2896)
> >> ==15738==    by 0x810A969: free_all_mem (misc2.c:1125)
> >> ==15738==    by 0x8140573: mch_exit (os_unix.c:3012)
> >> ==15738==    by 0x80DE4C8: getout (main.c:1342)
> >> ==15738==    by 0x80A56C3: ex_quit_all (ex_docmd.c:6281)
> >> ==15738==    by 0x809F8CB: do_one_cmd (ex_docmd.c:2623)
> >> ==15738==    by 0x809D18C: do_cmdline (ex_docmd.c:1099)
> >> ==15738==    by 0x812030E: nv_colon (normal.c:5179)
> >> ==15738==    by 0x8119B88: normal_cmd (normal.c:1152)
> >> ==15738==    by 0x80DE20A: main_loop (main.c:1181)
> >> ==15738==    by 0x80DDD5A: main (main.c:940)
> >>
> >> os_unix.c:
> >>
> >>   2890 # if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || 
> >> defined(PROTO)
> >>   2891     if (xterm_Shell != (Widget)0)
> >>   2892         XtDestroyWidget(xterm_Shell);
> >>   2893     if (xterm_dpy != NULL)
> >>   2894         XtCloseDisplay(xterm_dpy);
> >>   2895     if (app_context != (XtAppContext)NULL)
> >> !! 2896         XtDestroyApplicationContext(app_context);
> >>   2897 # endif
> >>   2898 # ifdef FEAT_X11
> >>   2899     if (x11_display != NULL && x11_display != xterm_dpy)
> >> !! 2900         XCloseDisplay(x11_display);
> >>   2901 # endif
> >>
> >> Line 2900 is using memory which was freed at line 2896
> >> according to valgrind. So it seems that
> >> XtDestroyApplicationContext(app_context) is also
> >> destroying x11_display.
> >>
> >> Attached patch fixes the error.
> >
> > Thanks.  I wonder if we can use #ifndef LESSTIF_VERSION  instead of
> > FEAT_GUI_MOTIF.  The other "#if 0" suggests that Solaris also has this
> > problem.  But I'm not sure about this specific code, since it was added
> > much later.
> 
> 
> Yes, #ifndef LESSTIF_VERSION is better than #ifndef FEAT_GUI_MOTIF.
> I tested it with both lesstif and Open Motif, it's fine.  After the attached
> patch, neither lesstif, nor Open Motif access freed memory.
> 
> Open Motif needs the same fix as for athena gui i.e. set x11_display
> to NULL after 'XtDestroyApplicationContext(app_context);' since it
> seems to take care of already calling 'XCloseDisplay(x11_display)'.
> 
> Lesstif and Open Motif also use uninitialized memory but I assume
> that's a problem in those libs and not with Vim.
> 
> There are several things not freed with all GUIs (athena, open motif
> lesstif, gtk2, gnome2) when exiting even with -DEXITFREE but that's
> not a major problem I think.  I fixed at least the following leak which
> happens at least for Motif and athena gui (patch: leak-gui_x11.c).
> 
> ==23613== 32 bytes in 1 blocks are definitely lost in loss record 34 of 126
> ==23613==    at 0x4022AB8: malloc (vg_replace_malloc.c:207)
> ==23613==    by 0x40A8C08: xpmParseDataAndCreate (in /usr/lib/libXm.so.2.0.1)
> ==23613==    by 0x40AA0A6: XpmCreateImageFromData (in /usr/lib/libXm.so.2.0.1)
> ==23613==    by 0x40AA342: XpmCreatePixmapFromData (in 
> /usr/lib/libXm.so.2.0.1)
> ==23613==    by 0x81C9E0E: gui_mch_init (gui_x11.c:1541)
> ==23613==    by 0x81BA6F1: gui_init (gui.c:457)
> ==23613==    by 0x81A56BD: set_termname (term.c:1845)
> ==23613==    by 0x81A609D: termcapinit (term.c:2514)
> ==23613==    by 0x81BA0BE: gui_start (gui.c:91)
> ==23613==    by 0x80DED45: main (main.c:634)

Yes, it's tough fixing all memory leaks for GUIs.  The documentation
isn't always clear about when memory can be freed.  I'll include the
ones the patched, thanks.

-- 
hundred-and-one symptoms of being an internet addict:
14. You start introducing yourself as "Jim at I-I-Net dot net dot au"

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui