1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: fix a file descriptor leak in os.read_bytes() (#10723)

This commit is contained in:
waspoza 2021-07-09 22:49:46 +02:00 committed by GitHub
parent 477d442f18
commit 075e09b10e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,6 +71,9 @@ struct C.dirent {
[manualfree]
pub fn read_bytes(path string) ?[]byte {
mut fp := vfopen(path, 'rb') ?
defer {
C.fclose(fp)
}
cseek := C.fseek(fp, 0, C.SEEK_END)
if cseek != 0 {
return error('fseek failed')
@ -85,7 +88,6 @@ pub fn read_bytes(path string) ?[]byte {
if nr_read_elements == 0 && fsize > 0 {
return error('fread failed')
}
C.fclose(fp)
res.trim(nr_read_elements * fsize)
return res
}