Skip to content

Commit

Permalink
Add custom deserialize method for UmfpackLU to avoid memory leak
Browse files Browse the repository at this point in the history
Fixes #15450
  • Loading branch information
andreasnoack committed Dec 19, 2018
1 parent 8b35e84 commit 185d33a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stdlib/SuiteSparse/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random", "DelimitedFiles", "Serialization"]
18 changes: 18 additions & 0 deletions stdlib/SuiteSparse/src/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import LinearAlgebra: Factorization, det, lu, ldiv!
using SparseArrays
import SparseArrays: nnz

import Serialization: AbstractSerializer, deserialize

import ..increment, ..increment!, ..decrement, ..decrement!

include("umfpack_h.jl")
Expand Down Expand Up @@ -192,6 +194,22 @@ function show(io::IO, F::UmfpackLU)
F.numeric != C_NULL && print(io, '\n', F.numeric)
end

function deserialize(s::AbstractSerializer, t::Type{UmfpackLU{Tv,Ti}}) where {Tv,Ti}
symbolic = deserialize(s)
numeric = deserialize(s)
m = deserialize(s)
n = deserialize(s)
colptr = deserialize(s)
rowval = deserialize(s)
nzval = deserialize(s)
status = deserialize(s)
obj = UmfpackLU{Tv,Ti}(symbolic, numeric, m, n, colptr, rowval, nzval, status)

finalizer(umfpack_free_symbolic, obj)

return obj
end

## Wrappers for UMFPACK functions

# generate the name of the C function according to the value and integer types
Expand Down

0 comments on commit 185d33a

Please sign in to comment.