Tk Source Code

View Ticket
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Ticket UUID: e42eef33ee88e54d48b7279d1392b7b260acf91e
Title: valgrind complains at wish startup
Type: Bug Version: core-8-6-branch, trunk
Submitter: fvogel Created on: 2017-08-22 20:09:28
Subsystem: 69. Events Assigned To: fvogel
Priority: 3 Low Severity: Minor
Status: Closed Last Modified: 2021-09-10 13:27:35
Resolution: Fixed Closed By: fvogel
    Closed on: 2021-09-10 13:27:35
Description:

f$ valgrind --tool=memcheck --leak-check=full /home/francois/Documents/tcltk/fossil/tcltk/bin/wish8.6
==21950== Memcheck, a memory error detector
==21950== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==21950== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==21950== Command: /home/francois/Documents/tcltk/fossil/tcltk/bin/wish8.6
==21950== 
==21950== Invalid read of size 1
==21950==    at 0x4C2D1D3: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21950==    by 0x5CEEC23: _XimUnRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x5CD5652: XUnregisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x4F77B13: InstantiateIMCallback (tkUnixEvent.c:681)
==21950==    by 0x5CEEB04: _XimRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x5CD55EB: XRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x4F77241: TkpOpenDisplay (tkUnixEvent.c:184)
==21950==    by 0x4EABC89: GetScreen (tkWindow.c:465)
==21950==    by 0x4EABA4A: CreateTopLevelWindow (tkWindow.c:348)
==21950==    by 0x4EAC6F1: TkCreateMainWindow (tkWindow.c:854)
==21950==    by 0x4EBB357: CreateFrame (tkFrame.c:582)
==21950==    by 0x4EBAE8F: TkListCreateFrame (tkFrame.c:468)
==21950==  Address 0x81b4e40 is 0 bytes inside a block of size 1 free'd
==21950==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21950==    by 0x5CE4B5F: XSetLocaleModifiers (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x4F77BFD: OpenIM (tkUnixEvent.c:731)
==21950==    by 0x4F77AE7: InstantiateIMCallback (tkUnixEvent.c:680)
==21950==    by 0x5CEEB04: _XimRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x5CD55EB: XRegisterIMInstantiateCallback (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==21950==    by 0x4F77241: TkpOpenDisplay (tkUnixEvent.c:184)
==21950==    by 0x4EABC89: GetScreen (tkWindow.c:465)
==21950==    by 0x4EABA4A: CreateTopLevelWindow (tkWindow.c:348)
==21950==    by 0x4EAC6F1: TkCreateMainWindow (tkWindow.c:854)
==21950==    by 0x4EBB357: CreateFrame (tkFrame.c:582)
==21950==    by 0x4EBAE8F: TkListCreateFrame (tkFrame.c:468)

I more than strongly suspect the fix for [7d967c68a0], i.e. [d4e818fadc], that was intended to fix Tk applications segmentation fault when ibus-daemon IME is restarted.

After a quick look at this patch I find a bit strange that InstantiateIMCallback()calls XUnregisterIMInstantiateCallback() while DestroyIMCallback()calls XRegisterIMInstantiateCallback(), but that is probably my misunderstanding.

In any case, something seems wrong in that patch.

User Comments: fvogel added on 2021-09-10 13:27:35:

Reported once more here in the Tcl tracker: https://core.tcl-lang.org/tcl/tktview/e649d9f567d765ecb0afe2446f350479d9360b1d

Since the fix is in libX11 I'm closing the ticket.


bll added on 2021-06-03 23:40:25:
Fixed in libX11 on June 3 2021.

fvogel added on 2019-03-05 21:19:20:

It seems that this was reported again, see [30672bcb71].


fvogel added on 2018-08-19 14:32:14:

The bug report at freedesktop just moved here.


fvogel added on 2017-09-11 20:23:09:

Bug report at freedesktop received an interesting comment today. I don't think there is any hope to see this fixed.


fvogel added on 2017-09-03 08:46:11:
Thanks for the explanation, this sounds correct indeed.

And thanks for the link as well. So this is a libX11 bug. I have added a comment in the freedesktop bugzilla ticket for cross reference.

Setting status of the present ticket to 'Pending' until this gets resolved in libX11.

bll added on 2017-08-23 20:58:47:
There's nothing unusual about the code.

I followed the logic of another implementation.  The logic you quote had me confused at first, but I worked through it and it is correct also.

- Once a XIM instance is instantiated, you don't need to watch for one to be registered.
- If you destroy a XIM instance, you need to register a callback in case a new one shows up again.

https://bugs.freedesktop.org/show_bug.cgi?id=81338
( https://github.com/mirror/libX11/blob/master/modules/im/ximcp/imInsClbk.c )

Looks like some people have run into this before, but the suggested patch has not been applied.

gcramer added on 2017-08-23 10:01:35:
I think that these complaints are not a problem, valgrind cannot resolve special memory hacks, and some libraries, not only X11, are using special memory hacks. In a big application you will see some more complaints of valgrind related to external libraries.