Tk Library Source Code

View Ticket
Login
Ticket UUID: 1230737
Title: No cleanup after failure in bwidget::init
Type: Bug Version: None
Submitter: nobody Created on: 2005-07-01 05:44:05
Subsystem: bwidget Assigned To: damonc
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-06-29 23:30:38
Resolution: Accepted Closed By: oehhar
    Closed on: 2009-06-29 16:30:38
Description:
I think there is a bug in Widget::init, line 66 (4th
from below): set pathopt($option)
[$Widget::_optiontype($type) $option $value [lindex
$optdesc 3]].
The command that gets executed can throw an exception
for example if an invalid value for an Enum is passed.
This exception should be caught to unset pathopt and
pathmod. As it is now, I am tempted to call this a
memory leak.

Example run showing the bug:
wish
% package require BWidget
1.7
% LabelFrame .lblf -side foo
bad side value "foo": must be left, right, top or bottom
% namespace eval ::Widget::LabelFrame {puts stderr
[lsort [info vars]]}
.lblf:mod .lblf:opt argc argv argv0 auto_index
auto_oldpath auto_path env errorCode errorInfo map
map.f map.l map:cmd opt optionClass optionExports sync
tcl_interactive tcl_libPath tcl_library tcl_patchLevel
tcl_pkgPath tcl_platform tcl_rcFileName tcl_version
tk_library tk_patchLevel tk_strictMotif tk_version

Solution:
if [catch {$Widget::_optiontype($type) $option $value
[lindex $optdesc 3]} msg] {
        if { [info exists pathopt] } {
            unset pathopt
        }
        unset pathmod
        return -code error "$msg"
} else {
        set pathopt($option) "$msg"
}
User Comments: oehhar added on 2009-06-29 23:30:38:
Thank you, very nice bug report.

Specially, because some lines upwards, the non-existance case is handled in a similar way.

Updated in cvs.