diff options
author | Jim Meyering <meyering@redhat.com> | 2008-03-10 22:08:34 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2008-03-10 22:08:34 +0000 |
commit | ea1b8c8764d150970c1203585d4cf8bf684afbf6 (patch) | |
tree | 760625d856048373d82ecd71dfe46ad4f26ff853 | |
parent | dd6d52363003ef0a2e7c2293bb6d0c5f1f829b6a (diff) | |
download | gcc-ea1b8c8764d150970c1203585d4cf8bf684afbf6.zip gcc-ea1b8c8764d150970c1203585d4cf8bf684afbf6.tar.gz gcc-ea1b8c8764d150970c1203585d4cf8bf684afbf6.tar.bz2 |
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
-rw-r--r-- | libjava/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/classpath/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/classpath/native/jni/classpath/jcl.c | 4 | ||||
-rw-r--r-- | libjava/gnu/classpath/natSystemProperties.cc | 3 |
4 files changed, 18 insertions, 1 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index cbffc7c..84ea6c0 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,9 @@ +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> * HACKING: Fix grep patterns. diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog index 1a39f6b..c3d8f63 100644 --- a/libjava/classpath/ChangeLog +++ b/libjava/classpath/ChangeLog @@ -1,3 +1,9 @@ +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> * doc/cp-hacking.texinfo: Fix spacing after periods. 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; diff --git a/libjava/gnu/classpath/natSystemProperties.cc b/libjava/gnu/classpath/natSystemProperties.cc index 089a14e..e259304 100644 --- a/libjava/gnu/classpath/natSystemProperties.cc +++ b/libjava/gnu/classpath/natSystemProperties.cc @@ -270,7 +270,10 @@ gnu::classpath::SystemProperties::insertSystemProperties (::java::util::Properti if (errno != ERANGE) break; buflen = 2 * buflen; + char *orig_buf = buffer; buffer = (char *) realloc (buffer, buflen); + if (buffer == NULL) + free (orig_buf); } if (buffer != NULL) free (buffer); |