Ignore:
Timestamp:
Mar 15, 2008, 3:34:56 PM (17 years ago)
Author:
dai
Message:

関数の戻り値の構造体など、一時メモリに保持された構造体のメンバに直接アクセスした場合、その一時メモリの解放が正常に行われないバグを修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/Threading/Thread.ab

    r400 r480  
    3030    throwingParamObject As Object
    3131
     32    needFreeStructurePointers As *VoidPtr
     33    countOfNeedFreeStructurePointers As Long
     34
    3235Public
    3336    Sub Thread()
     
    127130        '------------
    128131
     132        ' 構造体の一時メモリ退避用領域を作成
     133        needFreeStructurePointers = _System_malloc( 1 )
     134        countOfNeedFreeStructurePointers = 0
     135
    129136        'GCにスレッド開始を通知
    130137        _System_pobj_AllThreads->BeginThread(This, _System_GetSp() As *LONG_PTR)
     
    143150        'GCにスレッド終了を通知
    144151        _System_pobj_AllThreads->EndThread(This)
     152
     153        ' 構造体の一時メモリ退避用領域を破棄
     154        _System_free( needFreeStructurePointers )
    145155
    146156        '自身のスレッドハンドルを閉じる
     
    189199        Return throwingParamObject
    190200    End Function
     201
     202    Sub __AddNeedFreeTempStructure( structurePointer As VoidPtr )
     203        needFreeStructurePointers = _System_realloc( needFreeStructurePointers, ( countOfNeedFreeStructurePointers + 1 ) * SizeOf(VoidPtr) )
     204        needFreeStructurePointers[countOfNeedFreeStructurePointers] = structurePointer
     205        countOfNeedFreeStructurePointers ++
     206    End Sub
     207
     208    Sub __FreeTempStructure()
     209        Dim i = 0 As Long
     210        While i<countOfNeedFreeStructurePointers
     211            free( needFreeStructurePointers[i] )
     212            i++
     213        Wend
     214        countOfNeedFreeStructurePointers = 0
     215    End Sub
    191216
    192217
     
    389414
    390415End Namespace 'Detail
     416
     417Sub _System_AddNeedFreeTempStructure( structurePointer As VoidPtr )
     418    Thread.CurrentThread.__AddNeedFreeTempStructure( structurePointer )
     419End Sub
     420Sub _System_FreeTempStructure()
     421    Thread.CurrentThread.__FreeTempStructure()
     422End Sub
Note: See TracChangeset for help on using the changeset viewer.