Skip to content

Commit 97e1f95

Browse files
authored
fix Memory safety (#39)
1 parent 446a14b commit 97e1f95

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/LIBLINEAR.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function linear_train(
248248
# `_labels` being -1's, which seems better.
249249
_labels = Vector{Cint}(undef, m.nr_class)
250250
_labels .= -1 # initialize to some invalid state
251-
ccall((:get_labels, liblinear), Cvoid, (Ptr{Model},Ptr{Vector{Cint}}), ptr, pointer(_labels))
251+
ccall((:get_labels, liblinear), Cvoid, (Ptr{Model},Ptr{Vector{Cint}}), ptr, _labels)
252252
rho = solver_type == ONECLASS_SVM ? m.rho : 0.0
253253
model = LinearModel(solver_type, Int(m.nr_class), Int(m.nr_feature),
254254
w, _labels, reverse_labels, m.bias, rho)
@@ -292,13 +292,13 @@ function linear_predict(
292292
w_number = Int(model.nr_class == 2 && model.solver_type != MCSVM_CS ?
293293
1 : model.nr_class)
294294
decvalues = Array{Float64}(undef, w_number, ninstances)
295-
for i = 1:ninstances
295+
GC.@preserve decvalues for i = 1:ninstances
296296
if probability_estimates
297297
output = ccall((:predict_probability, liblinear), Float64, (Ptr{Cvoid}, Ptr{FeatureNode}, Ptr{Float64}),
298-
pointer(m), nodeptrs[i], pointer(decvalues, w_number*(i-1)+1))
298+
m, nodeptrs[i], pointer(decvalues, w_number*(i-1)+1))
299299
else
300300
output = ccall((:predict_values, liblinear), Float64, (Ptr{Cvoid}, Ptr{FeatureNode}, Ptr{Float64}),
301-
pointer(m), nodeptrs[i], pointer(decvalues, w_number*(i-1)+1))
301+
m, nodeptrs[i], pointer(decvalues, w_number*(i-1)+1))
302302
end
303303
output_int = round(Int,output)
304304

0 commit comments

Comments
 (0)