From 9181b0bd73c15a777d174e2db459223004854cc1 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 20 Feb 2024 22:22:26 -0600 Subject: [PATCH] fclose: Free the file buffer earlier. This moves the free() call for the file buffer before the malloc() that occurs when closing a temp file, which should at least slightly reduce the chances that the malloc() call fails. --- stdio.asm | 87 +++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/stdio.asm b/stdio.asm index d2f5a79..706c526 100644 --- a/stdio.asm +++ b/stdio.asm @@ -124,52 +124,10 @@ cl3 lda [stream] remove stream from the file list sta [p] lda [stream],Y sta [p],Y -cl3a ldy #FILE_flag if the file was opened by tmpfile then - lda [stream],Y - and #_IOTEMPFILE - beq cl3d - ph4 #nameBuffSize p = malloc(nameBuffSize) - jsl malloc - sta p - stx p+2 - ora p+2 if p == NULL then - bne cl3aa - lda #EOF flag error - sta err - bra cl3d just close the file -cl3aa lda p - sta grPathname grPathname = p - stx grPathname+2 - clc dsPathname = p+2 - adc #2 - bcc cl3b - inx -cl3b sta dsPathname - stx dsPathname+2 - lda #nameBuffSize p->size = nameBuffSize - sta [p] - ldy #FILE_file clRefnum = grRefnum = stream->_file - lda [stream],Y - beq cl3e - sta grRefnum - GetRefInfoGS gr GetRefInfoGS(gr) - bcs cl3c - lda grRefnum OSClose(cl) - sta clRefNum - OSClose cl - DestroyGS ds DestroyGS(ds) -cl3c ph4

size = nameBuffSize + sta [p] + ldy #FILE_file clRefnum = grRefnum = stream->_file + lda [stream],Y + beq cl4 + sta grRefnum + sta clRefNum + GetRefInfoGS gr GetRefInfoGS(gr) + bcs cl3e + OSClose cl OSClose(cl) + DestroyGS ds DestroyGS(ds) +cl3e ph4