#1951 Tcl_FSCreateDirectory() aborts

obsolete: 8.4b1
closed-fixed
Vince Darley
6
2002-07-08
2002-07-08
Reinhard Max
No

Tcl_FSCreateDirectory() aborts with:

UpdateStringProc should not be invoked for type path
Aborted (core dumped)

when the argument object has a refcount of 0, e.g.

Tcl_FSCreateDirectory(Tcl_NewStringObj("foo", -1));

The backtrace looks like this:

#0 0x400f7ab1 in kill () from /lib/libc.so.6
#1 0x400f78a8 in raise () from /lib/libc.so.6
#2 0x400f8edb in abort () from /lib/libc.so.6
#3 0x40091ade in Tcl_PanicVA () from /usr/lib/libtcl8.4.so
#4 0x40091b06 in Tcl_Panic () from /usr/lib/libtcl8.4.so
#5 0x4008fec6 in Tcl_GetStringFromObj () from
/usr/lib/libtcl8.4.so
#6 0x40085cbd in Tcl_FSJoinPath () from
/usr/lib/libtcl8.4.so
#7 0x4008579d in Tcl_FSGetPathType () from
/usr/lib/libtcl8.4.so
#8 0x40085721 in Tcl_FSGetPathType () from
/usr/lib/libtcl8.4.so
#9 0x40086dab in Tcl_FSGetNormalizedPath () from
/usr/lib/libtcl8.4.so
#10 0x40087290 in Tcl_FSGetFileSystemForPath () from
/usr/lib/libtcl8.4.so
#11 0x40086152 in Tcl_FSCreateDirectory () from
/usr/lib/libtcl8.4.so

Discussion

  • Vince Darley
    Vince Darley
    2002-07-08

    Logged In: YES
    user_id=32170

    This obviously isn't ideal, but calling Tcl_FSAnything in
    that way is clearly going to leak memory even if the
    result succeeds. The docs explicitly say that you
    should not call these APIs with refCounts of zero:

    "The \fBTcl_FS...\fR are objectified and may cache
    internal
    representations and other path-related strings (e.g. the
    current
    working directory). One side-effect of this is that one
    must be
    careful when passing in temporary objects with a
    refCount of zero.
    Under some circumstances, the filesystem code may
    wish to retain a
    reference to the passed in object, and so one must not
    assume that
    after any of these calls return, the object still has a
    refCount of
    zero - it may have been incremented. The practical
    lesson to learn
    from this is that \fBTcl_Obj *path = Tcl_NewStringObj
    (...) ;
    Tcl_FS...(path) ; Tcl_DecrRefCount(path)\fR is wrong,
    and may
    segfault. The 'path' must have its refCount incremented
    before
    passing it in, or decrementing it."

    I'll try to fix the crash in any case...

     
  • Reinhard Max
    Reinhard Max
    2002-07-08

    Logged In: YES
    user_id=124643

    Oops, sorry. I had overlooked that part of the manpage.

     
  • Vince Darley
    Vince Darley
    2002-07-08

    Logged In: YES
    user_id=32170

    Removed crash, but such a zero-refcount function call
    will simply return an error. Clarified docs.

     
  • Vince Darley
    Vince Darley
    2002-07-08

    • status: open --> closed-fixed