mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
os: fix memleak from getline on Linux (#18022)
This commit is contained in:
parent
e1e5076d94
commit
13b4cd9d58
1 changed files with 8 additions and 1 deletions
|
@ -571,7 +571,14 @@ pub fn get_raw_line() string {
|
|||
max := usize(0)
|
||||
buf := &char(0)
|
||||
nr_chars := unsafe { C.getline(&buf, &max, C.stdin) }
|
||||
return unsafe { tos(&u8(buf), if nr_chars < 0 { 0 } else { nr_chars }) }
|
||||
str := unsafe { tos(&u8(buf), if nr_chars < 0 { 0 } else { nr_chars }) }
|
||||
ret := str.clone()
|
||||
unsafe {
|
||||
if nr_chars > 0 && buf != 0 {
|
||||
C.free(buf)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue