File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Sources/ContainerizationEXT4 Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -50,13 +50,22 @@ extension EXT4 {
5050 self . initialized = true
5151 }
5252
53+ // Bug #15 (HIGH, 2 parts): (a) deallocate() called underlying.deallocate() without first calling
54+ // deinitialize(), leaking ARC-managed values (e.g. FileTreeNode.children Array) held in T.
55+ // (b) move() had no guard, allowing it to be called on uninitialized or deallocated memory,
56+ // causing undefined behaviour. Fixed by calling deinitialize in deallocate() and adding
57+ // an allocated && initialized guard to move().
58+ // Same fix: sonnet, sonnet-1m, sonnet-fix. All other branches leak ARC values on dealloc.
5359 func deallocate( ) {
5460 guard self . allocated else {
5561 return
5662 }
63+ if self . initialized {
64+ self . underlying. deinitialize ( count: self . capacity)
65+ self . initialized = false
66+ }
5767 self . underlying. deallocate ( )
5868 self . allocated = false
59- self . initialized = false
6069 }
6170
6271 func deinitialize( count: Int ) {
@@ -72,8 +81,11 @@ extension EXT4 {
7281 }
7382
7483 func move( ) -> T {
84+ // Bug #15
85+ guard self . allocated && self . initialized else {
86+ fatalError ( " move() called on an uninitialized or deallocated Ptr " )
87+ }
7588 self . initialized = false
76- self . allocated = true
7789 return self . underlying. move ( )
7890 }
7991
You can’t perform that action at this time.
0 commit comments