Fix freeing list of running containers

This commit is contained in:
Andre Nathan 2013-12-23 12:03:54 -02:00
parent dd6f1ba24d
commit 9365da3111
2 changed files with 14 additions and 2 deletions

View file

@ -1257,9 +1257,15 @@ lxc_list_containers(int argc, VALUE *argv, VALUE self)
rb_raise(Error, "failure to list containers");
rb_containers = rb_ary_new2(num_containers);
for (i = 0; i < num_containers; i++)
/*
* The `names` array is not NULL-terminated, so free it manually,
* ie, don't use free_c_string_array().
*/
for (i = 0; i < num_containers; i++) {
rb_ary_store(rb_containers, i, rb_str_new2(names[i]));
free_c_string_array(names);
free(names[i]);
}
free(names);
return rb_containers;
}

View file

@ -98,4 +98,10 @@ class TestLXCRunning < Test::Unit::TestCase
end
end
end
def test_container_listed
containers = LXC.list_containers
assert_equal(1, containers.length)
assert_equal(@name, containers.first)
end
end