1
0
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:
Emily Hudson 2020-06-27 16:00:27 +01:00 committed by GitHub
parent 190f970544
commit 1848eb0973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -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 {

View File

@ -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 }