From ea1b8c8764d150970c1203585d4cf8bf684afbf6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 10 Mar 2008 22:08:34 +0000 Subject: Don't leak upon failed realloc. libjava 2008-03-10 Jim Meyering Don't leak upon failed realloc. * gnu/classpath/natSystemProperties.cc (SystemProperties::insertSystemProperties): libjava/classpath 2008-03-10 Jim Meyering Don't leak upon failed realloc. * native/jni/classpath/jcl.c (JCL_realloc): Upon failed realloc, free the original buffer before throwing the exception. From-SVN: r133094 --- libjava/classpath/native/jni/classpath/jcl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libjava/classpath/native') diff --git a/libjava/classpath/native/jni/classpath/jcl.c b/libjava/classpath/native/jni/classpath/jcl.c index cd3f516..0180ab9f 100644 --- a/libjava/classpath/native/jni/classpath/jcl.c +++ b/libjava/classpath/native/jni/classpath/jcl.c @@ -1,5 +1,5 @@ /* jcl.c - Copyright (C) 1998, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1998, 2005, 2006, 2008 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -152,9 +152,11 @@ JCL_malloc (JNIEnv * env, size_t size) JNIEXPORT void *JNICALL JCL_realloc (JNIEnv * env, void *ptr, size_t size) { + void *orig_ptr = ptr; ptr = realloc (ptr, size); if (ptr == 0) { + free (orig_ptr); JCL_ThrowException (env, "java/lang/OutOfMemoryError", "malloc() failed."); return NULL; -- cgit v1.1