Skip to content

Commit

Permalink
Fix file leak when you BLOCK-OPEN and immediately BLOCK-CLOSE.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Nov 8, 2024
1 parent 20f0e7c commit 6651d5e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/post4.p4
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,11 @@ VARIABLE _str_buf_curr
: _block_flush _block_fd @ FLUSH-FILE DROP ;

\ (S: u -- ior )
: _block_seek _block_flush 1- _blk_size * S>D _block_fd @ REPOSITION-FILE ; $11 _pp!
: _block_seek
_block_flush DUP IF
1- _blk_size * S>D _block_fd @ REPOSITION-FILE
THEN
; $11 _pp!

\ (S: u -- | ⊥ )
: _block_read
Expand Down Expand Up @@ -1879,14 +1883,13 @@ VARIABLE _str_buf_curr

\ (S: -- )
: BLOCK-CLOSE
_block_fd @ 0<> _blk_number @ 0<> AND IF
_blk_number @ _block_write _block_fd @ CLOSE-FILE DROP
0 _block_fd ! _blk_free
THEN
_blk_number @ _block_write _block_fd @ CLOSE-FILE DROP
0 _block_fd ! _blk_free
;

\ (S: caddr u -- ior )
: BLOCK-OPEN
0 _blk_number !
2DUP R/W BIN OPEN-FILE IF
DROP R/W BIN CREATE-FILE ?DUP IF
NIP EXIT
Expand Down

0 comments on commit 6651d5e

Please sign in to comment.