Fix freeing list of running containers
This commit is contained in:
parent
dd6f1ba24d
commit
9365da3111
|
@ -1257,9 +1257,15 @@ lxc_list_containers(int argc, VALUE *argv, VALUE self)
|
||||||
rb_raise(Error, "failure to list containers");
|
rb_raise(Error, "failure to list containers");
|
||||||
|
|
||||||
rb_containers = rb_ary_new2(num_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]));
|
rb_ary_store(rb_containers, i, rb_str_new2(names[i]));
|
||||||
free_c_string_array(names);
|
free(names[i]);
|
||||||
|
}
|
||||||
|
free(names);
|
||||||
|
|
||||||
return rb_containers;
|
return rb_containers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,4 +98,10 @@ class TestLXCRunning < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_container_listed
|
||||||
|
containers = LXC.list_containers
|
||||||
|
assert_equal(1, containers.length)
|
||||||
|
assert_equal(@name, containers.first)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue