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:
parent
477d442f18
commit
075e09b10e
@ -71,6 +71,9 @@ struct C.dirent {
|
|||||||
[manualfree]
|
[manualfree]
|
||||||
pub fn read_bytes(path string) ?[]byte {
|
pub fn read_bytes(path string) ?[]byte {
|
||||||
mut fp := vfopen(path, 'rb') ?
|
mut fp := vfopen(path, 'rb') ?
|
||||||
|
defer {
|
||||||
|
C.fclose(fp)
|
||||||
|
}
|
||||||
cseek := C.fseek(fp, 0, C.SEEK_END)
|
cseek := C.fseek(fp, 0, C.SEEK_END)
|
||||||
if cseek != 0 {
|
if cseek != 0 {
|
||||||
return error('fseek failed')
|
return error('fseek failed')
|
||||||
@ -85,7 +88,6 @@ pub fn read_bytes(path string) ?[]byte {
|
|||||||
if nr_read_elements == 0 && fsize > 0 {
|
if nr_read_elements == 0 && fsize > 0 {
|
||||||
return error('fread failed')
|
return error('fread failed')
|
||||||
}
|
}
|
||||||
C.fclose(fp)
|
|
||||||
res.trim(nr_read_elements * fsize)
|
res.trim(nr_read_elements * fsize)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user