[kaffe] patch to check zlib return for OOM
jrandom
jrandom at i2p.net
Wed Sep 1 08:20:32 PDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
'lo all, here's another fix for a minor problem I ran into. I keep
an eye out for OOMs, but at the moment, some of the native zip code
doesn't check for that. I noticed this from my logs:
java.lang.Error: insufficient memory
at java.util.zip.Deflater.init (Deflater.java)
at java.util.zip.Deflater.<init> (Deflater.java:46)
at java.util.zip.GZIPOutputStream.<init>
(GZIPOutputStream.java:83)
[snip]
Trivial fixes checking zlib's return values for OOMs as well as
another check in Deflater.c (mirroring Inflater.c's handling)
attached. I couldn't find an explicit style guide ref for the
construct used (declaring a variable within a condition of a switch
block), so I just tried something that looked normal - change as
necessary, of course.
=jr
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.1
iQA/AwUBQTXoOBpxS9rYd+OGEQLRPQCgsTWvLVKQxz1nQ7Rk9b0BoN+13gQAoKO8
3J40DMILhMC4fI7o/n8GqodP
=+sqr
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: libraries/clib/zip/Inflater.c
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/clib/zip/Inflater.c,v
retrieving revision 1.13
diff -u -r1.13 Inflater.c
--- libraries/clib/zip/Inflater.c 18 Apr 2004 13:57:31 -0000 1.13
+++ libraries/clib/zip/Inflater.c 1 Sep 2004 15:16:23 -0000
@@ -71,6 +71,13 @@
case Z_NEED_DICT:
unhand(this)->needsDictionary = 1;
break;
+
+ case Z_MEM_ERROR:
+ {
+ errorInfo info;
+ postOutOfMemory(&info);
+ throwError(&info);
+ }
default:
SignalError("java.lang.Error", dstream->msg ? dstream->msg : "unknown error");
@@ -149,7 +156,19 @@
dstream->opaque = 0;
r = inflateInit2(dstream, val ? -WSIZEBITS : WSIZEBITS);
- if (r != Z_OK) {
+
+ switch (r) {
+ case Z_OK:
+ break;
+
+ case Z_MEM_ERROR:
+ {
+ errorInfo info;
+ postOutOfMemory(&info);
+ throwError(&info);
+ }
+
+ default:
SignalError("java.lang.Error", dstream->msg ? dstream->msg : "");
}
GET_STREAM(this) = dstream;
Index: libraries/clib/zip/Deflater.c
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/clib/zip/Deflater.c,v
retrieving revision 1.14
diff -u -r1.14 Deflater.c
--- libraries/clib/zip/Deflater.c 18 Apr 2004 13:57:31 -0000 1.14
+++ libraries/clib/zip/Deflater.c 1 Sep 2004 15:16:23 -0000
@@ -70,6 +70,13 @@
unhand(this)->finished = 1;
break;
+ case Z_MEM_ERROR:
+ {
+ errorInfo info;
+ postOutOfMemory(&info);
+ throwError(&info);
+ }
+
default:
SignalError("java.lang.Error", dstream->msg ? dstream->msg : "unknown error");
}
@@ -138,6 +145,11 @@
z_stream* dstream;
dstream = KMALLOC(sizeof(*dstream));
+ if (!dstream) {
+ errorInfo info;
+ postOutOfMemory(&info);
+ throwError(&info);
+ }
dstream->next_in = 0;
dstream->zalloc = kaffe_zalloc;
dstream->zfree = kaffe_zfree;
@@ -145,7 +157,18 @@
r = deflateInit2(dstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (val ? -WSIZEBITS : WSIZEBITS), 9, Z_DEFAULT_STRATEGY);
- if (r != Z_OK) {
+ switch (r) {
+ case Z_OK:
+ break;
+
+ case Z_MEM_ERROR:
+ {
+ errorInfo info;
+ postOutOfMemory(&info);
+ throwError(&info);
+ }
+
+ default:
SignalError("java.lang.Error", dstream->msg ? dstream->msg : "");
}
Index: ChangeLog
===================================================================
RCS file: /cvs/kaffe/kaffe/ChangeLog,v
retrieving revision 1.2691
diff -u -r1.2691 ChangeLog
--- ChangeLog 1 Sep 2004 10:31:03 -0000 1.2691
+++ ChangeLog 1 Sep 2004 15:16:24 -0000
@@ -1,3 +1,13 @@
+2004-09-01 jrandom <jrandom at i2p.net>
+
+ * kaffe/libraries/clib/zip/Inflater.c:
+ (inflate0): Check for memory allocation error.
+ (init): Likewise.
+
+ * kaffe/libraries/clib/zip/Deflater.c:
+ (deflate): Likewise.
+ (init): Likewise.
+
2004-09-01 Dalibor Topic <robilad at kaffe.org>
* kaffe/kaffevm/kaffe-gc/gc-mem.h (ASSERT_ONBLOCK):
More information about the kaffe
mailing list