fix filehandle leak in fileblock.yab

This commit is contained in:
Jim
2015-07-30 12:58:27 -07:00
parent edcdfd3231
commit 001a3d1aa4

View File

@@ -1,19 +1,18 @@
export sub openfile(filename$, recordlength, numberoffields) export sub openfile(fil$, recordlength, numberoffields)
// specify the record(block) length and number of fields for the file // specify the record(block) length and number of fields for the file
// returns the filehandle number used for other subs // returns the filehandle number used for other subs
static numfiles static numfiles
local x local x
x=open(fil$, "a")
x=open(filename$, "a")
if x=0 print"rror opening the file":return -1 // error opening the file if x=0 print"rror opening the file":return -1 // error opening the file
close x close x
numfiles=numfiles+1 numfiles=numfiles+1
dim f$(numfiles,50,2) // f$(numfile,1-50=fieldname$ dim f$(numfiles,50,2) // f$(numfile,1-50=fieldname$
dim f(numfiles,52) dim f(numfiles,52)
f$(numfiles,0,0)=filename$ f$(numfiles,0,0)=fil$
f(numfiles,51)=recordlength f(numfiles,51)=recordlength
f(numfiles,52)=numberoffields f(numfiles,52)=numberoffields
@@ -182,6 +181,7 @@ local a$
local z local z
local y local y
a$="" a$=""
local File
filename$=f$(filehandle,0,0) filename$=f$(filehandle,0,0)
File=open(filename$, "rb") File=open(filename$, "rb")
@@ -209,6 +209,7 @@ for y=0 to f(filehandle,52)
next next
rec=rec+1 rec=rec+1
close File
return rec return rec
end sub end sub
@@ -225,6 +226,7 @@ ret=tell(#x)
if ret=0 return ret if ret=0 return ret
ret= ret/(f(filehandle,51)+1) ret= ret/(f(filehandle,51)+1)
ret=int(ret) ret=int(ret)
close x
return ret return ret
end sub end sub