From 9365da3111e977de621a3d3a92ee11bbc002d16f Mon Sep 17 00:00:00 2001 From: Andre Nathan Date: Mon, 23 Dec 2013 12:03:54 -0200 Subject: [PATCH] Fix freeing list of running containers --- ext/lxc/lxc.c | 10 ++++++++-- test/test_lxc_running.rb | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/lxc/lxc.c b/ext/lxc/lxc.c index d077174..6ede153 100644 --- a/ext/lxc/lxc.c +++ b/ext/lxc/lxc.c @@ -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; } diff --git a/test/test_lxc_running.rb b/test/test_lxc_running.rb index 4b32152..d85579b 100644 --- a/test/test_lxc_running.rb +++ b/test/test_lxc_running.rb @@ -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