Don't use pointer after free()

This commit is contained in:
Andre Nathan 2014-03-06 10:19:17 -03:00
parent 7fcad3dba2
commit fd75ebc9a2
2 changed files with 7 additions and 2 deletions

View file

@ -993,7 +993,7 @@ container_cgroup_item(VALUE self, VALUE rb_key)
static VALUE
container_config_item(VALUE self, VALUE rb_key)
{
int len1, len2;
int len1, len2, mlines;
char *key, *value;
struct container_data *data;
struct lxc_container *container;
@ -1017,10 +1017,11 @@ container_config_item(VALUE self, VALUE rb_key)
rb_raise(Error, "unable to read configuration file");
}
rb_config = rb_str_new2(value);
mlines = value[len2-1] == '\n';
free(value);
/* Return a list in case of multiple lines */
return value[len2-1] == '\n' ? rb_str_split(rb_config, "\n") : rb_config;
return mlines ? rb_str_split(rb_config, "\n") : rb_config;
}
/*

View file

@ -36,6 +36,10 @@ class TestLXCCreated < Test::Unit::TestCase
assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr'))
end
def test_container_mount_points
assert_instance_of(Array, @container.config_item('lxc.mount.entry'))
end
def test_container_rename
new_name = "renamed_#{@name}"
renamed = @container.rename(new_name)