Tk Source Code

View Ticket
Login
Ticket UUID: 2b6398e983705a968236630b5c136be225ad9227
Title: Leak of the -locale value of entry, spinbox and text
Type: Bug Version: 9.1.0
Submitter: nab Created on: 2026-10-01 20:30:10
Subsystem: 23. Option Parsing Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-02 06:11:48
Resolution: Fixed Closed By: nab
    Closed on: 2026-10-02 06:11:48
Description:

Each time -locale is set on an entry, a spinbox, a text widget or a text tag, widget creation included, one Tcl_Obj is leaked.

SetLocale (TkLocaleOption) replaces *value with a new normalized object. These options have no objOffset, so DoObjConfig keeps no reference to the new object, and nothing frees it. ttk::entry is not affected, because its option has an objOffset.

Measured with a TCL_MEM_DEBUG build of trunk 2d659391fc:

  • entry .w; destroy .w: 114 bytes per widget (same for spinbox and text);
  • .e configure -locale ab_CD: 118 bytes per call;
  • frame .w; destroy .w and ttk::entry .w; destroy .w: 0.

Proposed fix: branch nab-wrap-locale, check-in aef871dbbd. For a custom option, DoObjConfig frees a new value object returned by the setProc when no slot keeps it (Tcl_BounceRefCount). This only acts when the setProc replaces the value with a new object, which only SetLocale does among the custom options of Tk.

New test entry-5.20 (constraint memory): 118 114 before the fix, 0 0 after. config.test, entry.test, spinbox.test and panedwindow.test pass (1295, 0), as do the ttk entry, spinbox and combobox tests (101, 0).

The same check-in is in revised_text b714df6a8a, where [$w brks] with a locale also leaked its argument; that part only concerns revised_text.

Checked on macOS (aqua) only.

User Comments: nab added on 2026-10-02 06:11:48:

Fixed in trunk [359b0a55fd] and core-9-0-branch [07207f7b91].


jan.nijtmans added on 2026-10-01 21:52:10:

Great catch.

+1 for merging to trunk and core-9-0-branch (and core-8-6-branch if you want)

Since it's really a bugfix in TK_OPTION_CUSTOM handling, extensions could suffering the same.