aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src/zlib.erl
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2012-03-15 12:13:28 +0100
committerSverker Eriksson <[email protected]>2012-03-15 12:30:34 +0100
commit2fbe8cc9b3f6f443ccccfaa485b05966aacc65d9 (patch)
tree2cc1d689b84b2025b66c9223c615ab014a3753e2 /erts/preloaded/src/zlib.erl
parent7484721f847e95380e66456b4a55e08481b570d8 (diff)
downloadotp-2fbe8cc9b3f6f443ccccfaa485b05966aacc65d9.tar.gz
otp-2fbe8cc9b3f6f443ccccfaa485b05966aacc65d9.tar.bz2
otp-2fbe8cc9b3f6f443ccccfaa485b05966aacc65d9.zip
Fix port leaks in zlib
zip,unzip,gzip,gunzip,compress and uncompress did not close the port when given invalid data argument. Fixed by putting close in "try-after". A closed port could in same cases get stuck in limbo due to data in io-queue. Fixed by adding a flush callback.
Diffstat (limited to 'erts/preloaded/src/zlib.erl')
-rw-r--r--erts/preloaded/src/zlib.erl72
1 files changed, 48 insertions, 24 deletions
diff --git a/erts/preloaded/src/zlib.erl b/erts/preloaded/src/zlib.erl
index 210532edac..71b730016d 100644
--- a/erts/preloaded/src/zlib.erl
+++ b/erts/preloaded/src/zlib.erl
@@ -349,10 +349,14 @@ getQSize(Z) ->
Compressed :: binary().
compress(Data) ->
Z = open(),
- deflateInit(Z, default),
- Bs = deflate(Z, Data, finish),
- deflateEnd(Z),
- close(Z),
+ Bs = try
+ deflateInit(Z, default),
+ B = deflate(Z, Data, finish),
+ deflateEnd(Z),
+ B
+ after
+ close(Z)
+ end,
iolist_to_binary(Bs).
-spec uncompress(Data) -> Decompressed when
@@ -364,10 +368,14 @@ uncompress(Data) ->
if
Size >= 8 ->
Z = open(),
- inflateInit(Z),
- Bs = inflate(Z, Data),
- inflateEnd(Z),
- close(Z),
+ Bs = try
+ inflateInit(Z),
+ B = inflate(Z, Data),
+ inflateEnd(Z),
+ B
+ after
+ close(Z)
+ end,
iolist_to_binary(Bs);
true ->
erlang:error(data_error)
@@ -383,10 +391,14 @@ uncompress(Data) ->
Compressed :: binary().
zip(Data) ->
Z = open(),
- deflateInit(Z, default, deflated, -?MAX_WBITS, 8, default),
- Bs = deflate(Z, Data, finish),
- deflateEnd(Z),
- close(Z),
+ Bs = try
+ deflateInit(Z, default, deflated, -?MAX_WBITS, 8, default),
+ B = deflate(Z, Data, finish),
+ deflateEnd(Z),
+ B
+ after
+ close(Z)
+ end,
iolist_to_binary(Bs).
-spec unzip(Data) -> Decompressed when
@@ -394,10 +406,14 @@ zip(Data) ->
Decompressed :: binary().
unzip(Data) ->
Z = open(),
- inflateInit(Z, -?MAX_WBITS),
- Bs = inflate(Z, Data),
- inflateEnd(Z),
- close(Z),
+ Bs = try
+ inflateInit(Z, -?MAX_WBITS),
+ B = inflate(Z, Data),
+ inflateEnd(Z),
+ B
+ after
+ close(Z)
+ end,
iolist_to_binary(Bs).
-spec gzip(Data) -> Compressed when
@@ -405,10 +421,14 @@ unzip(Data) ->
Compressed :: binary().
gzip(Data) ->
Z = open(),
- deflateInit(Z, default, deflated, 16+?MAX_WBITS, 8, default),
- Bs = deflate(Z, Data, finish),
- deflateEnd(Z),
- close(Z),
+ Bs = try
+ deflateInit(Z, default, deflated, 16+?MAX_WBITS, 8, default),
+ B = deflate(Z, Data, finish),
+ deflateEnd(Z),
+ B
+ after
+ close(Z)
+ end,
iolist_to_binary(Bs).
-spec gunzip(Data) -> Decompressed when
@@ -416,10 +436,14 @@ gzip(Data) ->
Decompressed :: binary().
gunzip(Data) ->
Z = open(),
- inflateInit(Z, 16+?MAX_WBITS),
- Bs = inflate(Z, Data),
- inflateEnd(Z),
- close(Z),
+ Bs = try
+ inflateInit(Z, 16+?MAX_WBITS),
+ B = inflate(Z, Data),
+ inflateEnd(Z),
+ B
+ after
+ close(Z)
+ end,
iolist_to_binary(Bs).
-spec collect(zstream()) -> iolist().