Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2014-07-11
04:49
[3479689] Plug memory leak due to incomplete bug fix. check-in: 2830730e99 user: dgp tags: trunk
2012-01-28
04:58 • Closed ticket [3479689fff]: shimmer 0-refcount to path can segfault plus 7 o... artifact: 9b2dff2b16 user: dgp
2012-01-26
23:43 • Ticket [3479689fff]: 4 changes artifact: d98f5b2ac5 user: dgp
01:31 • Ticket [3479689fff]: 4 changes artifact: 52d7a932ce user: dgp
01:30 • Ticket [3479689fff]: 4 changes artifact: 886e7fd8ce user: dgp
00:48 • Ticket [3479689fff]: 4 changes artifact: 2b95168b31 user: dgp
2012-01-25
17:43 • New ticket [3479689fff]. artifact: 13f200db8c user: dgp

shimmer 0-refcount to path can segfault

Closed / Fixed3479689fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2012-01-25 17:43:37
Tcl_FSConvertToPathType(NULL, Tcl_NewStringObj("a//b",-1));

will crash at least on unix systems in a -enable-symbols=mem build
of Tcl.

This passes a 0-refcount value to SetFsPathFromAny() which
passes it on to Tcl_FSJoinToPath().  As documented, on exit
Tcl_FSJoinToPath() frees the value, but then SetFsPathFromAny()
continues on, trying to build a "path" intrep in the freed space.  BOOM!
dgpplain2012-01-26 00:48:27
In the more usual build, this won't crash, but will result in
building up the path value in a Tcl_Obj that's been returned to
the free pool.  Eventually that will get reallocated to some other
use, and you'll see memory corruption effects as two different owners
battle over the use of the struct.
dgpplain2012-01-26 01:30:06
The quick and easy fix is to bracket the
call to Tcl_FsJoinToPath() with refcount incr/decr:

    pathPtr->refCount++;
    transPtr = Tcl_FSJoinToPath(pathPtr, 0, NULL);
    pathPtr->refCount--;
dgpplain2012-01-26 01:31:23
The more attractive fix is to take Tcl_FSJoinToPath()
back behind the barn and shoot it in the head.

Why oh why do we document interfaces we can plainly
see are broken?
dgpplain2012-01-26 23:43:56
Simple fix committed for 8.5.12
dgpplain2012-01-28 04:58:05
allow_comments - 1

Better fix on trunk with refactoring of the *Join*Path*
routines into more usable interfaces.
Log in (anonymous is fine) to add a comment.