mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix memleak from getline on Linux (#18022)
This commit is contained in:
parent
e1e5076d94
commit
13b4cd9d58
@ -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…
Reference in New Issue
Block a user