ext/libsvm/libsvm.c in rb-libsvm-1.1.2 vs ext/libsvm/libsvm.c in rb-libsvm-1.1.3
- old
+ new
@@ -338,15 +338,17 @@
static VALUE cModel_predict(VALUE obj,VALUE example) {
struct svm_node *x;
struct svm_model *model;
double class;
-
+
x = example_to_internal(example);
Data_Get_Struct(obj, struct svm_model, model);
class = svm_predict(model, x);
-
+
+ free(x);
+
return rb_float_new(class);
}
static VALUE cModel_predict_probability(VALUE obj,VALUE example) {
struct svm_node *x;
@@ -369,9 +371,10 @@
estimates = rb_ary_new();
for (i = 0; i < model->nr_class; i++)
rb_ary_push(estimates, rx_from_double(c_estimates[i]));
free(c_estimates);
+ free(x);
target = rb_ary_new();
rb_ary_push(target, rb_float_new(class));
rb_ary_push(target, estimates);
return target;