Skip to content

Commit

Permalink
Call h5d_vlen_reclaim to release resource (#436)
Browse files Browse the repository at this point in the history
Call h5d_vlen_reclaim to release resource
  • Loading branch information
musm committed Nov 2, 2017
1 parent 0d19462 commit 9a916c4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1368,15 +1368,16 @@ function read{S<:String}(obj::DatasetOrAttribute, ::Type{Array{S}})
close(objtype)
end
if isempty(sz)
ret = S[]
h5t_close(memtype_id)
return S[]
else
dspace = dataspace(obj)
ret = Array{S}(sz)
if isvar
# Variable-length
buf = Vector{Cstring}(len)
h5t_set_size(memtype_id, H5T_VARIABLE)
readarray(obj, memtype_id, buf)
# FIXME? Who owns the memory for each string? Julia v0.6+ won't free it.
for i = 1:len
ret[i] = unsafe_string(buf[i])
end
Expand All @@ -1395,9 +1396,14 @@ function read{S<:String}(obj::DatasetOrAttribute, ::Type{Array{S}})
src += ilen
end
end
try
h5d_vlen_reclaim(memtype_id, dspace.id, H5P_DEFAULT, buf)
finally
close(dspace)
h5t_close(memtype_id)
end
return ret
end
h5t_close(memtype_id)
ret
end
read{S<:CharType}(obj::DatasetOrAttribute, ::Type{Array{S}}) = read(obj, Array{stringtype(S)})
# Empty Array of strings
Expand Down

0 comments on commit 9a916c4

Please sign in to comment.