mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen,map: fix leaks in keys()
and for x in y
This commit is contained in:
parent
190f970544
commit
1848eb0973
@ -448,7 +448,7 @@ pub fn (mut m map) delete(key string) {
|
||||
// Returns all keys in the map.
|
||||
// TODO: add optimization in case of no deletes
|
||||
pub fn (m &map) keys() []string {
|
||||
mut keys := [''].repeat(m.len)
|
||||
mut keys := []string{ len:m.len }
|
||||
mut j := 0
|
||||
for i := u32(0); i < m.key_values.len; i++ {
|
||||
if m.key_values.keys[i].str == 0 {
|
||||
|
@ -841,7 +841,10 @@ fn (mut g Gen) for_in(it ast.ForInStmt) {
|
||||
g.writeln(', $key, &($val_styp[]){ $zero }));')
|
||||
}
|
||||
g.stmts(it.stmts)
|
||||
g.writeln('/* for in map cleanup*/ string_free(&$key);')
|
||||
g.writeln('}')
|
||||
g.writeln('/*for in map cleanup*/')
|
||||
g.writeln('array_free(&$keys_tmp);')
|
||||
} else if it.cond_type.has_flag(.variadic) {
|
||||
g.writeln('// FOR IN cond_type/variadic')
|
||||
i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var }
|
||||
|
Loading…
Reference in New Issue
Block a user