Commit ea1b8c87 by Jim Meyering Committed by Tom Tromey

Don't leak upon failed realloc.

libjava
2008-03-10  Jim Meyering  <meyering@redhat.com>
        Don't leak upon failed realloc.
        * gnu/classpath/natSystemProperties.cc
        (SystemProperties::insertSystemProperties):
libjava/classpath
2008-03-10  Jim Meyering  <meyering@redhat.com>
        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
parent dd6d5236
2008-03-10 Jim Meyering <meyering@redhat.com>
Don't leak upon failed realloc.
* gnu/classpath/natSystemProperties.cc
(SystemProperties::insertSystemProperties):
2008-03-06 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> 2008-03-06 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* HACKING: Fix grep patterns. * HACKING: Fix grep patterns.
......
2008-03-10 Jim Meyering <meyering@redhat.com>
Don't leak upon failed realloc.
* native/jni/classpath/jcl.c (JCL_realloc): Upon failed realloc,
free the original buffer before throwing the exception.
2008-03-09 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> 2008-03-09 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* doc/cp-hacking.texinfo: Fix spacing after periods. * doc/cp-hacking.texinfo: Fix spacing after periods.
......
/* jcl.c /* 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. This file is part of GNU Classpath.
...@@ -152,9 +152,11 @@ JCL_malloc (JNIEnv * env, size_t size) ...@@ -152,9 +152,11 @@ JCL_malloc (JNIEnv * env, size_t size)
JNIEXPORT void *JNICALL JNIEXPORT void *JNICALL
JCL_realloc (JNIEnv * env, void *ptr, size_t size) JCL_realloc (JNIEnv * env, void *ptr, size_t size)
{ {
void *orig_ptr = ptr;
ptr = realloc (ptr, size); ptr = realloc (ptr, size);
if (ptr == 0) if (ptr == 0)
{ {
free (orig_ptr);
JCL_ThrowException (env, "java/lang/OutOfMemoryError", JCL_ThrowException (env, "java/lang/OutOfMemoryError",
"malloc() failed."); "malloc() failed.");
return NULL; return NULL;
......
...@@ -270,7 +270,10 @@ gnu::classpath::SystemProperties::insertSystemProperties (::java::util::Properti ...@@ -270,7 +270,10 @@ gnu::classpath::SystemProperties::insertSystemProperties (::java::util::Properti
if (errno != ERANGE) if (errno != ERANGE)
break; break;
buflen = 2 * buflen; buflen = 2 * buflen;
char *orig_buf = buffer;
buffer = (char *) realloc (buffer, buflen); buffer = (char *) realloc (buffer, buflen);
if (buffer == NULL)
free (orig_buf);
} }
if (buffer != NULL) if (buffer != NULL)
free (buffer); free (buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment