cgen,map: fix leaks in `keys()` and `for x in y`
parent
190f970544
commit
1848eb0973
|
@ -448,7 +448,7 @@ pub fn (mut m map) delete(key string) {
|
||||||
// Returns all keys in the map.
|
// Returns all keys in the map.
|
||||||
// TODO: add optimization in case of no deletes
|
// TODO: add optimization in case of no deletes
|
||||||
pub fn (m &map) keys() []string {
|
pub fn (m &map) keys() []string {
|
||||||
mut keys := [''].repeat(m.len)
|
mut keys := []string{ len:m.len }
|
||||||
mut j := 0
|
mut j := 0
|
||||||
for i := u32(0); i < m.key_values.len; i++ {
|
for i := u32(0); i < m.key_values.len; i++ {
|
||||||
if m.key_values.keys[i].str == 0 {
|
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.writeln(', $key, &($val_styp[]){ $zero }));')
|
||||||
}
|
}
|
||||||
g.stmts(it.stmts)
|
g.stmts(it.stmts)
|
||||||
|
g.writeln('/* for in map cleanup*/ string_free(&$key);')
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
|
g.writeln('/*for in map cleanup*/')
|
||||||
|
g.writeln('array_free(&$keys_tmp);')
|
||||||
} else if it.cond_type.has_flag(.variadic) {
|
} else if it.cond_type.has_flag(.variadic) {
|
||||||
g.writeln('// FOR IN cond_type/variadic')
|
g.writeln('// FOR IN cond_type/variadic')
|
||||||
i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var }
|
i := if it.key_var in ['', '_'] { g.new_tmp_var() } else { it.key_var }
|
||||||
|
|
Loading…
Reference in New Issue