Zlib resource deallocation
Carsten Schultz
carsten@REDACTED
Mon Feb 9 15:08:52 CET 2004
Hi Erlangers!
Supposing I have
withZ(F) ->
Z = zlib:open(),
ok = zlib:deflateInit(Z, default),
Ret = F(Z),
zlib:deflateEnd(Z),
zlib:close(Z),
Ret.
What happen if F throws {'EXIT', ...}? Will the zlib resources be
freed? If not so, what is a proper way to handle this? How about the
following?
withZ(F) ->
Z = zlib:open(),
ok = zlib:deflateInit(Z, default),
case catch F(Z) of
Ret ->
zlib:deflateEnd(Z),
zlib:close(Z),
case Ret of
{'EXIT', Err} -> throw(Ret);
_ -> Ret
end
end.
Or to simplify the question: What would bne the best way to write
withZ?
Greetings,
Carsten
--
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.codimi.de/
PGP/GPG key on the pgp.net key servers,
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20040209/91066800/attachment.bin>
More information about the erlang-questions
mailing list