From 0c85fc752731667fc0874f2913341c5a721a5579 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 5 Dec 2009 15:51:12 -0700 Subject: [PATCH] throw OutOfMemoryError if malloc returns null pointer --- classpath/java-util-zip.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/classpath/java-util-zip.cpp b/classpath/java-util-zip.cpp index 219abf0741..a7d969839a 100644 --- a/classpath/java-util-zip.cpp +++ b/classpath/java-util-zip.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, Avian Contributors +/* Copyright (c) 2008-2009, Avian Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided @@ -20,6 +20,11 @@ Java_java_util_zip_Inflater_make (JNIEnv* e, jclass, jboolean nowrap) { z_stream* s = static_cast(malloc(sizeof(z_stream))); + if (s == 0) { + throwNew(e, "java/lang/OutOfMemoryError", 0); + return 0; + } + memset(s, 0, sizeof(z_stream)); int r = inflateInit2(s, (nowrap ? -15 : 15)); @@ -86,6 +91,11 @@ Java_java_util_zip_Deflater_make (JNIEnv* e, jclass, jboolean nowrap, jint level) { z_stream* s = static_cast(malloc(sizeof(z_stream))); + if (s == 0) { + throwNew(e, "java/lang/OutOfMemoryError", 0); + return 0; + } + memset(s, 0, sizeof(z_stream)); int r = deflateInit2(s, level, (nowrap ? -15 : 15));