* Don't leak upon failed realloc
@ 2008-03-08 15:12 Jim Meyering
2008-03-10 18:50 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Jim Meyering @ 2008-03-08 15:12 UTC (permalink / raw)
To: java-patches
Hi,
Here are two fixes (separate patches) to avoid leaks upon failed realloc.
These are the affected files:
libjava/gnu/classpath/natSystemProperties.cc | 3 +++
libjava/classpath/native/jni/classpath/jcl.c | 4 +++-
--------------------------------------------------------------------
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
libjava/ChangeLog | 6 ++++++
libjava/gnu/classpath/natSystemProperties.cc | 3 +++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index cbffc7c..079d37e 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,9 @@
+2008-03-08 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/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);
--
1.5.4.3.485.g2b05
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
libjava/classpath/ChangeLog | 6 ++++++
libjava/classpath/native/jni/classpath/jcl.c | 4 +++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog
index 87ffc23..1b00fa3 100644
--- a/libjava/classpath/ChangeLog
+++ b/libjava/classpath/ChangeLog
@@ -1,3 +1,9 @@
+2008-03-02 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-01-27 Bernhard Fischer <rep.dot.nop@gmail.com>
* java/util/SimpleTimeZone.java (SimpleTimeZone): Fix typo in comment.
diff --git a/libjava/classpath/native/jni/classpath/jcl.c b/libjava/classpath/native/jni/classpath/jcl.c
index cd3f516..0180ab9 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;
--
1.5.4.3.485.g2b05
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-03-10 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-08 15:12 Don't leak upon failed realloc Jim Meyering
2008-03-10 18:50 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).