Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-03-27
13:06 • Ticket [48150cdad2] Command creation with overwrite (prevention against endless ... artifact: 85f1232fbf user: sebres
13:04 • New ticket [48150cdad2]. artifact: 289c40752f user: sebres

Command creation with overwrite (prevention against endless loop by its recreation via trace) is affected by drastic mem-leak

Open48150cdad29ca6c6db7c1d0c86a18110dfe43d40Created 2 years agoUpdated 2 years ago
Descriptionwiki2025-03-27 13:04:53
The way how command gets (re)created is affected by drastic mem-leak, due to prevention against endless loop by its recreation via trace. The responsible place of code in TclCreateObjCommandInNs, the same is valid for other functions like Tcl_CreateCommand etc.

PoC:

  namespace eval A { proc test {} {puts test}; namespace export test }
  proc recreate {args} { namespace eval ::B {
    namespace import ::A::test }; 
    trace add command ::B::test delete recreate
  }
  timerate { recreate; proc ::B::test {} {}; rename ::B::test {} } 10000
(and lets grow the mem-usage)

By regular deletion it'd restore everything back, but not by overwrite, that wins and this prevention causes that the new command overwrites the old at any cost without proper clean-up, no traces but also no deletion callback, no release for internal members, nothing excepting ckfree for cmdPtr.

I'd rather expects that 2nd run of trace is avoided and the command gets deleted and overwritten properly (and surely without the leak). Also if command gets restored again now via deletion callback, it shall win and attempt overwrite must cause something like "cannot create - existing command restored after deletion, avoid endless loop".

sebres Ticket [48150cdad2]: 3 changes [History diff]2025-03-27 13:06:25
Log in (anonymous is fine) to add a comment.